Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active January 14, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaguiini/480e0cf741d3d01ae518f6442bcfefde to your computer and use it in GitHub Desktop.
Save zaguiini/480e0cf741d3d01ae518f6442bcfefde to your computer and use it in GitHub Desktop.
How to flatten a list using reduce and recursion
const flattenList = (array) => {
return array.reduce((flat, next) => {
return flat.concat(Array.isArray(next) ? flattenList(next) : next)
}, [])
}
@sibelius
Copy link

spread?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment