Skip to content

Instantly share code, notes, and snippets.

@pragyandas
Last active February 27, 2017 19:27
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 pragyandas/7bcc471f228fd54440c7580dd0e6645a to your computer and use it in GitHub Desktop.
Save pragyandas/7bcc471f228fd54440c7580dd0e6645a to your computer and use it in GitHub Desktop.
Flatten an Array using Reduce and Array.prototype.concat
/**
* Flattens an array which contains array elements
* flatten([1,2,[3,4]]) // [1,2,3,4]
* @method flatten
* @param {Array} list
* @return {Array}
*/
const flatten = (list) => list.reduce((recur,next)=>Array.prototype.concat.call(recur,next),[])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment