Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created December 17, 2019 07:42
Show Gist options
  • Save andrIvash/bb570965684487505b13773174c5b20b to your computer and use it in GitHub Desktop.
Save andrIvash/bb570965684487505b13773174c5b20b to your computer and use it in GitHub Desktop.
tree to flat array
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