Class nodeList
has a static method fromArray(array)
that generates an algebraic list from provided array.
Class nodeList
instance has methods:
toArray()
that generates an array from an algebraic listfilter(predicate)
that returns a new algebraic list where list nodes'head
values satisfy providedpredicate
functionmap(mapper)
that returns a new algebraic list withmapper
function applied to each list nodes'head
Function treeBranchMaxSum(root)
traverses provided binary tree root
and returns maximal branch sum from root to leaf.
Function sumTreeValues(root)
traverses provided binary tree root
and returns sum of all tree nodes' value
properties.
Function treeHeight(root)
traverses provided binary tree root
and returns length of the longest branch not counting root as a unit of length (e.g. if branch is 0124
and 0
is root, then branche's length is 3
).
Function printTree(root)
traverses a provided tree (not necessarily binary) and returns the tree represented as a multiline string where each row is a depth level of the tree. Tree node's value
property is either a string or a number. Tree node's children
property is an array containing all of the node's children.
Example tree node :
Node { value: X, children: [] }
Example input:
- 2
- 7
- 2
- 6
- 5
- 11
- 5
- 9
- 4
- 9
- 7
Example output:
2\n7 5\n2 6 9\n5 11 4
2
7 5
2 6 9
5 11 4
Scripts by V.