Last active
October 8, 2023 23:45
-
-
Save tansongyang/9695563ad9f1fa5309b0af8aa6b3e7e3 to your computer and use it in GitHub Desktop.
An implementation of Cartesian product using lodash/fp
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
// Based on this gist: https://gist.github.com/ChrisJefferson/cb8db2a4c67a9506c56c | |
// JS Bin: https://jsbin.com/cefopi/edit?js,console | |
const cartesianProduct = (...rest) => | |
_.reduce((a, b) => | |
_.flatMap(x => | |
_.map(y => | |
x.concat([y]) | |
)(b) | |
)(a) | |
)([[]])(rest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment