Last active
August 6, 2020 20:38
-
-
Save kyleshevlin/04379b6a4237ccd81cf78dc8f005a3c9 to your computer and use it in GitHub Desktop.
Recursive Reducer done imperatively
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, 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