Created
July 13, 2018 13:56
-
-
Save downzer0/d712abc700742c6d065d29c0ec8fa02e to your computer and use it in GitHub Desktop.
Depth-first object searching
This file contains 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
// 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