Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Created May 3, 2018 10:26
Show Gist options
  • Save karl-gustav/a72e0137c64ef9f149a20a6d3a527af0 to your computer and use it in GitHub Desktop.
Save karl-gustav/a72e0137c64ef9f149a20a6d3a527af0 to your computer and use it in GitHub Desktop.
.reduce() alternative to .flatMap()
const flattenArray = (x, y) => (x || []).concat(y);
// Usage:
[[1,2],[3],[4]].reduce(flattenArray);
// Or:
[[1,2],[3],[4]].reduce((x, y) => (x || []).concat(y));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment