Skip to content

Instantly share code, notes, and snippets.

@Grytsak
Created September 12, 2017 09:12
Show Gist options
  • Select an option

  • Save Grytsak/1838449fe538437f3a793141c9806232 to your computer and use it in GitHub Desktop.

Select an option

Save Grytsak/1838449fe538437f3a793141c9806232 to your computer and use it in GitHub Desktop.
function find(source, name) {
for (key in source)
{
var item = source[key];
if (item.name == name)
return item;
// Item not returned yet. Search its children by recursive call.
if (item.children)
{
var subresult = find(item.children, name);
// If the item was found in the subchildren, return it.
if (subresult)
return subresult;
}
}
// Nothing found yet? return null.
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment