Skip to content

Instantly share code, notes, and snippets.

@tansongyang
Last active October 8, 2023 23:45
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tansongyang/9695563ad9f1fa5309b0af8aa6b3e7e3 to your computer and use it in GitHub Desktop.
Save tansongyang/9695563ad9f1fa5309b0af8aa6b3e7e3 to your computer and use it in GitHub Desktop.
An implementation of Cartesian product using lodash/fp
// 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