Tree

DataStructure. Tree

Simple tree structure. It doesn't have any special rules to it and looks something like this:
Tree {
 root: {
  value: 1,
  children: [{
   value: 2,
   children: [...]
  },{
   value: 3,
   children: [...]
  }]
 }
}

Constructor

new Tree()

The tree has to start with a single parent, the "root" of the tree.
Source:

Methods

add(value, parentValue)

Add a node to the tree and define the parent node
Parameters:
Name Type Description
value * Value of new node
parentValue * Parent node
Source:

traverse(callback)

Traverse the tree and call a function on each node in the tree.
Parameters:
Name Type Description
callback
Source: