Last active
May 9, 2019 18:26
-
-
Save jourdanrodrigues/7404e8fc6f48ef444364c061d71969a0 to your computer and use it in GitHub Desktop.
Function to flatten an array object.
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
/** | |
* Function to flatten an array object | |
* Example: [[1, 2, [3]], 4] -> [1, 2, 3, 4] | |
* @param: {Array} array: Array object to be flattened | |
*/ | |
function flatten (array) { | |
return array.reduce((flat, next) => flat.concat(next instanceof Array ? flatten(next) : next), []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment