Last active
March 3, 2017 13:16
-
-
Save tobiaslins/46c512f5bd65631fe38e6091cbbd8099 to your computer and use it in GitHub Desktop.
Flat array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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