Skip to content

Instantly share code, notes, and snippets.

@tobiaslins
Last active March 3, 2017 13:16
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 tobiaslins/46c512f5bd65631fe38e6091cbbd8099 to your computer and use it in GitHub Desktop.
Save tobiaslins/46c512f5bd65631fe38e6091cbbd8099 to your computer and use it in GitHub Desktop.
Flat array
const testArray = [[1,2,[3]],4]
const flatArray = (arr) => arr.reduce((a, b) => {
const newValue = Array.isArray(b) ? flat(b) : b
return a.concat(newValue)
}, [])
console.log(flatArray(testArray))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment