Skip to content

Instantly share code, notes, and snippets.

@zarcode
Last active December 19, 2017 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zarcode/af2bb3db0bfff424706664fe8c58f4cd to your computer and use it in GitHub Desktop.
Save zarcode/af2bb3db0bfff424706664fe8c58f4cd to your computer and use it in GitHub Desktop.
Array utility functions
/**
* 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