Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalicarus/9521690 to your computer and use it in GitHub Desktop.
Save digitalicarus/9521690 to your computer and use it in GitHub Desktop.
//TODO: add object checks
searchTree function (node, getChildren, test) {
function find (node, parent) {
var kids = getChildren(node), i, ret = null;
if (test(node)) { return { parent: parent, match: node }; }
if (kids.length < 1) { return null; }
for (i=0; i<kids.length; i++) {
ret = find(kids[i], node);
if (ret) { return ret; }
}
return null;
}
return find (node);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment