Skip to content

Instantly share code, notes, and snippets.

@camjocotem
Created June 27, 2023 09:27
Show Gist options
  • Select an option

  • Save camjocotem/a84d3e1668d966c339d5fc5cb3f72a33 to your computer and use it in GitHub Desktop.

Select an option

Save camjocotem/a84d3e1668d966c339d5fc5cb3f72a33 to your computer and use it in GitHub Desktop.
Recursive FlatMap
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