Skip to content

Instantly share code, notes, and snippets.

@perborgen
Last active August 30, 2016 19:31
Show Gist options
  • Save perborgen/9c15fe909ff693b736e13317fecd5ddd to your computer and use it in GitHub Desktop.
Save perborgen/9c15fe909ff693b736e13317fecd5ddd to your computer and use it in GitHub Desktop.
Node Search
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