Skip to content

Instantly share code, notes, and snippets.

@nshahpazov
Forked from mgechev/promise-dfs.js
Last active November 2, 2015 11:48
Show Gist options
  • Save nshahpazov/598e8499491327941973 to your computer and use it in GitHub Desktop.
Save nshahpazov/598e8499491327941973 to your computer and use it in GitHub Desktop.
function traverse(node) {
return Promise.all(R.map(c => Promise.resolve(c), node.children))
.then((nodes) => {
return Promise.all(nodes.map(traverse))
.then(R.reduce((prev, arr) => arr.concat(prev), []))
.then(els => els.concat(nodes));
});
}
traverse(document.body).then(R.map(e => console.log(e.tagName)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment