Skip to content

Instantly share code, notes, and snippets.

@downzer0
Created July 13, 2018 13:56
Show Gist options
  • Save downzer0/d712abc700742c6d065d29c0ec8fa02e to your computer and use it in GitHub Desktop.
Save downzer0/d712abc700742c6d065d29c0ec8fa02e to your computer and use it in GitHub Desktop.
Depth-first object searching
// depth-first object search
const findNode = (scores, opDiv, found = []) => {
for (let org in scores) {
if (scores[org].path === opDiv) {
found.push(scores[org]);
return found[0];
}
if (typeof scores[org] === 'object') {
findNode(scores[org].children, opDiv, found);
}
}
return found[0];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment