Last active
August 6, 2020 20:52
-
-
Save kyleshevlin/ed4025f807235a4559a67d47981c0890 to your computer and use it in GitHub Desktop.
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
function flattenFolderTree(folders) { | |
return folders.reduce((acc, folder) => { | |
const {children, ...rest} = folder; | |
if (!children || !children.length) { | |
return [...acc, rest]; | |
} | |
return [...acc, rest, ...flattenFolderTree(children)]; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something I have been considering when using reducers is to expose the reducer itself as the tool.
The only benefit to this is it would let someone dot chain off the Array.