Created
June 27, 2023 09:27
-
-
Save camjocotem/a84d3e1668d966c339d5fc5cb3f72a33 to your computer and use it in GitHub Desktop.
Recursive FlatMap
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
| const flatten = (routes) => { | |
| return routes.reduce((acc, r) => { | |
| if(r.childRoutes && r.childRoutes.length) { | |
| acc = acc.concat(flatten(r.childRoutes)); | |
| } else { | |
| acc.push(r); | |
| } | |
| return acc; | |
| }, []) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment