Skip to content

Instantly share code, notes, and snippets.

@Giagnus64
Last active February 26, 2020 22:19
Show Gist options
  • Save Giagnus64/6027aa3aacf924dd94a2025268203e05 to your computer and use it in GitHub Desktop.
Save Giagnus64/6027aa3aacf924dd94a2025268203e05 to your computer and use it in GitHub Desktop.
PreOrder DFS
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