Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the cartesian product of multiple sets
// Thanks to
const cartesianProduct = (...sets) =>
sets.reduce((sets, set) => sets.flatMap(x => => [...x, y])), [[]]);
['a', 'b', 'c'],
['x', 'y', 'z'],
// [
// ["a", "x"],
// ["a", "y"],
// ["a", "z"],
// ["b", "x"],
// ["b", "y"],
// ["b", "z"],
// ["c", "x"],
// ["c", "y"],
// ["c", "z"],
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.