Graph

DataStructure. Graph

A graph can hold multiple nodes with multiple lines connected to each other

Multiple "nodes" (A, B, C, D, ...) that are connected with lines. These nodes are going to look like this:
Node {
 value: ...,
 lines: [(Node), (Node), ...]
}
The entire graph will look like this:
Graph {
 nodes: [
  Node {...},
  Node {...},
  ...
 ]
}

Usage example:

var graph = new Graph();
graph.addNode(1);
graph.addNode(2);
graph.addLine(1, 2);

Constructor

new Graph()

Start with an empty array to store all nodes
Source:

Methods

addLine(startValue, endValue)

Connect two nodes by making a "line" form one to the other.
Parameters:
Name Type Description
startValue * Start node of line
endValue * End node of line
Source:
Throws:
Both nodes need to exist
Type
Error

addNode(value)

Add a node without any lines
Parameters:
Name Type Description
value * Value for new node
Source:

find(value) → {*}

Lookup nodes in the graph. Simply search through all nodes to find one with matching value.
Parameters:
Name Type Description
value * Value of node that should match
Source:
Returns:
Type
*