Skip to content

Instantly share code, notes, and snippets.

@blasten
Created January 21, 2016 02:07
Show Gist options
  • Save blasten/5a5033e93e2f3e91df6b to your computer and use it in GitHub Desktop.
Save blasten/5a5033e93e2f3e91df6b to your computer and use it in GitHub Desktop.
// Recursive depth first search
function RecursiveDFSTraversal(root, fn, fnArgs) {
if (!root) {
return;
}
fnArgs = fn(root, fnArgs);
for (var i = 0; fnArgs && i < root.children.length; i++) {
RecursiveDFSTraversal(root.children[i], fn, fnArgs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment