It finds the first child of root that matches continuePredicate.
The function gets passed a depth of 1 to begin with. It recurses, looking for the next sub-child, etc.
If it can't find a child, it stops.
This is different to 'find' functions, which exhausively search all possible child nodes, regardless of position in tree.
constpath = 'a.aa.aaa'.split('.'); constpred = (nodeValue, depth) => { if (nodeValue === path[0]) { path.shift(); // Remove first element returntrue; } returnfalse; }
// Assuming we have a tree of string values: // a // - aa // - aaa // - ab // b // - ba for (constcoffollow(tree, pred)) { // Returns nodes: a, aa and then aaa }
Search through children in a path-like manner.
It finds the first child of
root
that matchescontinuePredicate
. The function gets passed a depth of 1 to begin with. It recurses, looking for the next sub-child, etc.If it can't find a child, it stops.
This is different to 'find' functions, which exhausively search all possible child nodes, regardless of position in tree.