Last active
October 3, 2018 19:31
-
-
Save herbertpimentel/9c3716b6c767fb7b4f296a889a46cefa to your computer and use it in GitHub Desktop.
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
/** | |
* @description Flats an array with any nested level deep. e.g. [[1,2,[3]],4] -> [1,2,3,4] | |
*/ | |
export const flatArray = (arr) => { | |
return (arr || []).reduce((previous, current) => | |
// call it recursivelly, adds support to nested arrays any level deep | |
previous.concat(Array.isArray(current) ? flatArray(current) : current) | |
, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment