Global

Methods

Tree(Node) → {Tree}

Tree factory.

Source:
Parameters:
Name Type Description
Node Node
Returns:
Type:
Tree

bfs(root, visit, getChildren) → {Object}

Perform a breadth-first search on a graph or tree.

Source:
Parameters:
Name Type Description
root Object

The root node to start the search from.

visit function

A function to call for each visited node, return true to end up the search.

getChildren function

A function to get the children of a node.

Returns:
Type:
Object

The node found

dfs(root, visit, getChildren) → {Object}

Perform a depth-first search on a graph or tree.

Source:
Parameters:
Name Type Description
root Object

The root node to start the search from.

visit function

A function to call for each visited node, return true to end up the search.

getChildren function

A function to get the children of a node.

Returns:
Type:
Object

The node found

find(predicate)

Find a node by BFS.

Source:
Parameters:
Name Type Description
predicate predicateFunction

Type Definitions

predicateFunction(node) → {boolean}

A closure function to be called to check the data of each node whether meets certain condition

Source:
Parameters:
Name Type Description
node Node
Returns:
Type:
boolean