Skip to content

Instantly share code, notes, and snippets.

@albertorestifo
Created May 1, 2016 07:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertorestifo/55455e43b2056f1603657a2bc0b2fed0 to your computer and use it in GitHub Desktop.
Save albertorestifo/55455e43b2056f1603657a2bc0b2fed0 to your computer and use it in GitHub Desktop.
Multi-level flatten function
var flatten = arr => arr.reduce((p, c) => p.concat(Array.isArray(c) ? flatten(c) : c), []);
/**
* Credit goes to Benjamin Gruenbaum, from his comment on this article: http://www.2ality.com/2016/04/promise-trees.html
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment