Created
February 23, 2018 11:53
-
-
Save mauriciosoares/2093a4d36c7cce8387aedf328ce2ba7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 array = [[1,2,[3]],4]; | |
function flatten(arr) { | |
return arr.reduce((newArray, item) => { | |
return [ | |
...newArray, | |
...(Array.isArray(item) ? flatten(item) : [item]) | |
] | |
}, []); | |
} | |
flatten(array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment