Last active
August 29, 2015 13:57
-
-
Save digitalicarus/9521690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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