Created
September 12, 2017 09:12
-
-
Save Grytsak/1838449fe538437f3a793141c9806232 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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