# JavaScript Graphs

August 02, 2018 | 1 min read

Similar to currying, graphs were one of those things I wanted to know, but never took the time to learn. Well until now of course!

A graph is a non-linear data structure. Graphs have nodes and edges. Nodes are the values while the edges connect the values to each other. I like to think of this a social network. Think of the graph as facebook, the nodes are people, and the edges are connections. You are a node and will be connected with your friends, who are also nodes. Everyone has a connection with their friends. Almost like one big giant spider web

There are a few different kinds

**WIP**

**LET ME SEE DA CODE**
For those who just want to see the code, here it is!

```
class Node {
constructor(value){
this.value = value;
this.edges = []
}
}
class UndirectedGraph {
constructor(){
this.vertices = {}
}
addNode(value){
if(!this.vertices[value])
return this.vertices[value] = new Node(value)
}
addEdge(from, to, weight){
if(this.vertices[from] && this.vertices[to]){
this.vertices[from].edges.push({node: to, weight: weight})
this.vertices[to].edges.push({node: from, weight: weight})
}
return
}
}
```