Skip to content

Instantly share code, notes, and snippets.

@mekhami
Last active November 1, 2018 18:21
Show Gist options
  • Save mekhami/0bdb31708fe08ac6593f20cdc68d5c88 to your computer and use it in GitHub Desktop.
Save mekhami/0bdb31708fe08ac6593f20cdc68d5c88 to your computer and use it in GitHub Desktop.
const findNode = (id, group) => {
let stack = new Array(group)
while (stack.length) {
let node = stack.pop()
if (node.id === id) { return node }
else if (node.children && node.children.length) {
node.children.forEach(child => stack.push(child))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment