Skip to content

Instantly share code, notes, and snippets.

@tobiaslins tobiaslins/flatarray.js
Last active Mar 3, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.