t.dfs()

perform a depth-first search, executing the given callback at each node.

t.dfs(node, [config], function(node, par, ctrl) {
/* ... */
})

in the pre-order case, dfs() doesn't process child nodes until after the
callback. so if you need to traverse an unknown tree, say a directory
structure, you can start with just the root, and add child nodes as you go
by appending them to this.children in the callback function.

node:
object where the search will start. this could also be an array of
objects

config:
if this is an object w/ the 'order' property set to 'post', a
post-order traversal will be performed. this is generally worse
performance, but the callback has access to the return values of its
child nodes.

callback (last argument):
function to be executed at each node. the arguments are:

node: the current node

par: the current node's parent

ctrl: control object. setting the stop property of this will end
the search, setting the cutoff property of this will not visit any
children of this node

ret: return values of child nodes. this is only set if dfs() is
called with the order property set to post.

t.filter()

given a tree, return a tree of the same structure made up of the objects
returned by the callback which is executed at each node. if, however, at a
given node the callback returns a falsy value, then the current node and all
of its descendents will be pruned from the output tree.

t.filter(node, function(node, par) {
/* ... */
})

node:
object where the traversal will start. this could also be an array of
objects

callback (last argument):
function to be executed at each node. this must return an object or a
falsy value if the output tree should be pruned from the current node
down. the filter function takes care of setting children. the
arguments are:

node: the current node

par: the current node's parent. note that this is the parent from
the new tree that's being created.