Created
December 17, 2019 07:42
-
-
Save andrIvash/bb570965684487505b13773174c5b20b to your computer and use it in GitHub Desktop.
tree to flat array
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
const flattenDeep = (items) => ( | |
items.reduce((acc, val) => { | |
if (val.children && val.children.length) { | |
acc.push(val); | |
return acc.concat(flattenDeep(val.children)); | |
} | |
return acc.concat(val); | |
}, []) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment