Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Last active August 6, 2020 20:38
Show Gist options
  • Save kyleshevlin/04379b6a4237ccd81cf78dc8f005a3c9 to your computer and use it in GitHub Desktop.
Save kyleshevlin/04379b6a4237ccd81cf78dc8f005a3c9 to your computer and use it in GitHub Desktop.
Recursive Reducer done imperatively
function flattenFolderTree(folders, gatheringArray = []) {
folders.forEach(folder => {
const {children, ...rest} = folder
gatheringArray.push(rest)
if (children && children.length) {
flattenFolderTree(children, gatheringArray)
}
})
return gatheringArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment