Skip to content

Instantly share code, notes, and snippets.

View hinsencamp's full-sized avatar

Fabian Hinsenkamp hinsencamp

View GitHub Profile
generateRandomNetwork(graph, 10);
writeToJSON(graph.graph, "graph");
a -> { b c }
b -> { a d }
c -> { a }
d -> { b c }
graph.get("Fabian").addConnection(graph.get("Rey"));
graph.get("Fabian").addConnection(graph.get("Ellie"));
graph.get("Fabian").addConnection(graph.get("Cassi"));
graph.get("Ellie").addConnection(graph.get("Cassi"));
const graph = new Graph();
graph.addNode(fabian);
graph.addNode(rey);
graph.addNode(ellie);
graph.addNode(cassi);
const fabian = new Node({ name: "Fabian" });
const rey = new Node({ name: "Rey" });
const ellie = new Node({ name: "Ellie" });
const cassi = new Node({ name: "Cassi" });
Node.prototype.addConnection = function(user) {
if (!this.friends[user.name]) {
this.friends[user.name] = { name: user.name };
user.addConnection(this);
}
};
function Node(user) {
this.name = user.name;
this.friends = {};
}
Graph.prototype.addUser = function(user) {
this.graph[user.name] = user;
};
Graph.prototype.getNode = function(name) {
return this.graph[name];
};
function Graph() {
this.graph = {};
}