Skip to content

Instantly share code, notes, and snippets.

@albertorestifo
Created May 1, 2016 07:02
Show Gist options
  • 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