Created
March 9, 2017 19:38
-
-
Save nitely/d8cd0e2953e3741d22ebfbff6c178029 to your computer and use it in GitHub Desktop.
Lame JS puzzle #3
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
| /* | |
| This is just a BFS. It only works if the node to find is unique (ie: has an ID) | |
| */ | |
| function findNode(curr, node) { | |
| if (curr == null) | |
| return; | |
| if (curr.isEqualNode(node)) | |
| return curr; | |
| for (let n of curr.childNodes) { | |
| let foundNode = findNode(n, node); | |
| if (foundNode != null) | |
| return foundNode; | |
| } | |
| } | |
| let waldo = document.querySelectorAll('.waldo'); | |
| let root = document.querySelector('body') | |
| console.log(findNode(root, waldo)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment