Last active
December 19, 2017 10:18
-
-
Save zarcode/af2bb3db0bfff424706664fe8c58f4cd to your computer and use it in GitHub Desktop.
Array utility functions
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
/** | |
* Flattens the multidimensional array | |
* @param {Array} array - some multidimensional array | |
* @returns {Array} flattened array | |
*/ | |
function flatten(array) { | |
return array.reduce(function(acc, curr) { | |
var items = Array.isArray(curr)? flatten(curr) : [curr]; | |
return acc.concat(items); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment