Skip to main content
Loading...

More JavaScript Posts

results =
{
 "11345240":"Media Comment-80e47004-1719-493a-af69-a43b2652b41c",
 "11345282":"zoom_3_22_21.mp4",
 "11345303":"Recording-2.m4a",
 "11345348":"February 12%2C 2021.mp4",
 "11345826":"Lecture_Rousso_Chapter_06-2.pptx",
 "11345933":"Themes_InClassAssigment.pptx",
 "11346193":"Agenda – Week of March23.pptx",
 "11346318":"MUJS 2370 SP2021 Updated Rhythm Changes Drills Bb - Score.pdf",
 "11346319":"MUJS 2370 SP2021 Updated Rhythm Changes Drills C - Score.pdf",
 "11346322":"MUJS 2370 SP2021 Updated Rhythm Changes Drills Eb - Score.pdf",
 "11346323":"MUJS 2370 Updated Rhythm Changes Drills Bass - Score.pdf",
 "11346381":"Anthropology with colored highlighter analysis - Mar 22 2021 - 10-36 AM.pdf",
 "11346449":"Anthropology with colored highlighter analysis - Mar 22 2021 - 10-36 AM.pdf",
 "11346450":"MUJS 2370 SP2021 Updated Rhythm Changes Drills Bb - Score.pdf",
 "11346451":"MUJS 2370 SP2021 Updated Rhythm Changes Drills C - Score.pdf",
 "11346453":"MUJS 2370 SP2021 Updated Rhythm Changes Drills Eb - Score.pdf",
 "11346454":"MUJS 2370 Updated Rhythm Changes Drills Bass - Score.pdf",
 "11346495":"Steinel chromatic ornamentation étude rhythm changes - Aug 23 2020 - 12-19 PM.pdf",
 "11346532":"Media Comment-136242b4-7f2c-4d5d-8aa4-091f07e797cf",
 "11346581":"2019 Trust Based Relationship Intervention Manual.pdf",
 "11346584":"TBRI ppt.pptx",
 "11346593":"Trauma informed care.ppt"
}

function NewTab(testing) {
  window.open(testing, "_blank");
}

for(test in results) {
  var testing = 'https://unt.instructure.com/files/' + test + '/download';
  NewTab(testing);
  //window.open = 'https://unt.instructure.com/files/' + test + '/download';
}
class Graph {
  constructor(directed = true) {
    this.directed = directed;
    this.nodes = [];
    this.edges = new Map();
  }

  addNode(key, value = key) {
    this.nodes.push({ key, value });
  }

  addEdge(a, b, weight) {
    this.edges.set(JSON.stringify([a, b]), { a, b, weight });
    if (!this.directed)
      this.edges.set(JSON.stringify([b, a]), { a: b, b: a, weight });
  }

  removeNode(key) {
    this.nodes = this.nodes.filter(n => n.key !== key);
    [...this.edges.values()].forEach(({ a, b }) => {
      if (a === key || b === key) this.edges.delete(JSON.stringify([a, b]));
    });
  }

  removeEdge(a, b) {
    this.edges.delete(JSON.stringify([a, b]));
    if (!this.directed) this.edges.delete(JSON.stringify([b, a]));
  }

  findNode(key) {
    return this.nodes.find(x => x.key === key);
  }

  hasEdge(a, b) {
    return this.edges.has(JSON.stringify([a, b]));
  }

  setEdgeWeight(a, b, weight) {
    this.edges.set(JSON.stringify([a, b]), { a, b, weight });
    if (!this.directed)
      this.edges.set(JSON.stringify([b, a]), { a: b, b: a, weight });
  }

  getEdgeWeight(a, b) {
    return this.edges.get(JSON.stringify([a, b])).weight;
  }

  adjacent(key) {
    return [...this.edges.values()].reduce((acc, { a, b }) => {
      if (a === key) acc.push(b);
      return acc;
    }, []);
  }

  indegree(key) {
    return [...this.edges.values()].reduce((acc, { a, b }) => {
      if (b === key) acc++;
      return acc;
    }, 0);
  }

  outdegree(key) {
    return [...this.edges.values()].reduce((acc, { a, b }) => {
      if (a === key) acc++;
      return acc;
    }, 0);
  }
}


const g = new Graph();

g.addNode('a');
g.addNode('b');
g.addNode('c');
g.addNode('d');

g.addEdge('a', 'c');
g.addEdge('b', 'c');
g.addEdge('c', 'b');
g.addEdge('d', 'a');

g.nodes.map(x => x.value);  // ['a', 'b', 'c', 'd']
[...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);
// ['a => c', 'b => c', 'c => b', 'd => a']

g.adjacent('c');            // ['b']

g.indegree('c');            // 2
g.outdegree('c');           // 1

g.hasEdge('d', 'a');        // true
g.hasEdge('a', 'd');        // false

g.removeEdge('c', 'b');

[...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);
// ['a => c', 'b => c', 'd => a']

g.removeNode('c');

g.nodes.map(x => x.value);  // ['a', 'b', 'd']
[...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);
// ['d => a']

g.setEdgeWeight('d', 'a', 5);
g.getEdgeWeight('d', 'a');  // 5