Skip to content

Instantly share code, notes, and snippets.

@mrizwanghuman
Created June 22, 2017 21:06
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 mrizwanghuman/f990fd0385194e039a41c4b897c4280e to your computer and use it in GitHub Desktop.
Save mrizwanghuman/f990fd0385194e039a41c4b897c4280e to your computer and use it in GitHub Desktop.
Flatten an array of arbitrarily nested arrays
var unflatten =[[1,2,[3]],4]
let flatten = (flattenArray) => flattenArray.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
console.log(flatten(unflatten));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment