Last active
August 30, 2016 19:31
-
-
Save perborgen/9c15fe909ff693b736e13317fecd5ddd to your computer and use it in GitHub Desktop.
Node Search
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
function search(nodeTree, query) { | |
for (var i = 0, len = nodeTree.length; i < len; i++) { | |
if (nodeTree[i].name === query) { | |
return nodeTree[i]; | |
} | |
if (nodeTree[i].children.length > 0) { | |
var new_search = search(nodeTree[i].children, query); | |
if (new_search) { | |
return new_search; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment