Skip to content

Instantly share code, notes, and snippets.

@gjohnson
Created November 4, 2011 04:48
Show Gist options
  • Save gjohnson/1338679 to your computer and use it in GitHub Desktop.
Save gjohnson/1338679 to your computer and use it in GitHub Desktop.
Traversing Goodness
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));
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