Created
November 4, 2011 04:48
-
-
Save gjohnson/1338679 to your computer and use it in GitHub Desktop.
Traversing Goodness
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
| var tree = { | |
| id: null, | |
| children: [ | |
| { | |
| id: null, | |
| children: [ | |
| { | |
| id: null, | |
| children:[ | |
| { | |
| id: null, | |
| children: [ | |
| { | |
| id: null, | |
| children: [ | |
| { | |
| id: 1, | |
| children: [] | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| }; | |
| function _(what,node){ | |
| return !!node && node.id === what ? node : ( | |
| node && node.children && | |
| _(what, node.children.shift()) | |
| ) | |
| }; | |
| console.log(_(1, tree)); |
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 _(a,b){return!!b&&b.id===a?b:b&&b.children&&_(a,b.children.shift())} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment