Created
May 3, 2018 10:26
-
-
Save karl-gustav/a72e0137c64ef9f149a20a6d3a527af0 to your computer and use it in GitHub Desktop.
.reduce() alternative to .flatMap()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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