Build a Class with methods that can traverse a tree. Each method should return a different collections of data from the data tree.
###Methods:
getAllNames
returns an Array with all of the values of the Name property for each and every node. e.g.["Tom", "Dick", "Harry"]
getAllAges
returns an Array with all of the values of the Age property for each and every node. e.g.[9, 8, 7, 6]
getLeafNames
returns an Array with only the values of the Name property from nodes that are leafs. A leaf node is an object with no children nodes.getLeafAges
returns an Array with only the values of the Age property from nodes that are leafs.findAllParentsNames
returns an array of names that belong to all non-leaf nodes.findAllParentsAges
returns an array of ages that belong to all non-leaf nodes.findName(String)
finds a node by it's name property and returns that entire object. e.g.{name: 'Roger Moore', has_parent: true, is_leaf: false, children: []}
findAge
do not implement this but please declare it on the Traverse prototype chain so that the first few tests pass.
This tree is in JSON
format.
An example of a node inside of the tree:
{
name: "Roger Moore", // have a String with a name value, e.g. "Russel"
has_parent: null, // can be of True, False, or Null values.
has_children: true, // Boolean, if True then the children property Array will be populated
children: [ // An Array of Objects that look contain more nodes.
{ // Nodes are objects that look similar to this object.
name: "Sean Connery",
has_parent: true,
has_children: false,
children: []
}
]
}
- fork and clone this repo
- does forget to
npm install
- run
gulp
to keep your tasks running - do work inside of
traverse.js
- make each test pass in order (important as some tests rely on working code)