Created
February 5, 2019 10:15
-
-
Save bluurn/c2092cb5d48aa2dd05a8f407c73e1ca5 to your computer and use it in GitHub Desktop.
JS: Implementation of Cartesian product
This file contains 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 cartesian = (...arrays) => arrays.reduce((cartesianPart, array) => ( | |
[].concat(... | |
cartesianPart.map(cartesianPartTuple => | |
array.map(it => cartesianPartTuple.concat(it)) | |
) | |
) | |
), [[]]); | |
console.log(cartesian([1,2], [3,4], [5,6])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment