class Graph { constructor() { this._storage = {}; } addNode(node) { this._storage[node] = node; } contains(node) { return !!this._storage[node]; } remove(node) { if (this._storage[node]) { for (var i = 0; i < this._storage[node].edges.length; i++) { if (this._storage[node].edges[i] === node){ delete this._storage[node].edges[i] } } delete this._storage[node] } } addEdge(fromNode, toNode) { if (this._storage[fromNode] && this._storage[toNode]) { this._storage[fromNode][edges][toNode] = toNode; this._storage[toNode][edges][fromNode] = fromNode; } } hasEdge(fromNode, toNode) { if (this._storage[fromNode][edges][toNode]) { return !!this._storage[fromNode][edges][toNode]; } } removeEdge(fromNode, toNode) { if (this._storage[fromNode][edges][toNode] && this._storage[fromNode][edges][toNode]) { delete this._storage[fromNode][edges][toNode]; delete this._storage[toNode][edges][fromNode]; } } }