Created
April 23, 2021 20:22
-
-
Save djfm/284e5cc6d017f1276da0ba417e36efcd to your computer and use it in GitHub Desktop.
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
// Flatten an array of nodes, returning all nodes | |
// of the tree without their children. | |
const flattenNodeTree = (node) => { | |
const { children, ...otherProps } = node; | |
if (!children) { | |
return [{ ...otherProps }]; | |
} | |
return [{ ...otherProps }, ...[].concat(...children.map(flattenNodeTree))]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment