Created
February 28, 2017 17:47
-
-
Save mikepenzin/713173f7a420423000d9a8eb907bc66e to your computer and use it in GitHub Desktop.
Depth-First-Search algorithm
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
// Create a function that, given a DOM Element on the page, | |
// will visit the element itself and all of its descendents | |
// (not just its immediate children). For each element visited, | |
// the function should pass that element to a provided callback function. | |
// The arguments to the function should be: | |
// a DOM element | |
// a callback function (that takes a DOM element as its argument) | |
function Traverse(p_element,p_callback) { | |
p_callback(p_element); | |
var list = p_element.children; | |
for (var i = 0; i < list.length; i++) { | |
Traverse(list[i],p_callback); // recursive call | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment