Last active
February 26, 2020 22:19
-
-
Save Giagnus64/6027aa3aacf924dd94a2025268203e05 to your computer and use it in GitHub Desktop.
PreOrder DFS
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
const preOrderHelper = node => { | |
//push value onto array FIRST | |
treeValues.push(node.value); | |
//recursively call function on all node children | |
if (node.children.length !== 0) { | |
node.children.forEach(child => { | |
preOrderHelper(child); | |
}); | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment