Created
October 24, 2019 11:47
-
-
Save MatthewTrout/61dc1e5fd42ee8365980375129165bcd to your computer and use it in GitHub Desktop.
es6 array flatten
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
export const flatten = (arr) => { | |
return arr.reduce((acc, curr) => { | |
const val = Array.isArray(curr) ? flatten(curr) : [curr]; | |
return [...acc, ...val]; | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment