Creates a generator that yields all possible pairs between elements of two iterables. If only one iterable is provided, it creates pairs from the same iterable.
Type of elements in the first iterable
Type of the second iterable or undefined
Optional
Optional second iterable. If omitted, pairs are created from elements in h
A function that takes an iterable and returns a generator of pairs
Pairs [a, b] representing the cartesian product of the two iterables
// Cartesian product of two arraysconst pairs = [...cartesianProduct([4, 5, 6])([1, 2, 3])]// Result: [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]] Copy
// Cartesian product of two arraysconst pairs = [...cartesianProduct([4, 5, 6])([1, 2, 3])]// Result: [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]]
// Cartesian product of array with itselfconst selfPairs = [...cartesianProduct()([1, 2, 3])]// Result: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] Copy
// Cartesian product of array with itselfconst selfPairs = [...cartesianProduct()([1, 2, 3])]// Result: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]
Creates a generator that yields all possible pairs between elements of two iterables. If only one iterable is provided, it creates pairs from the same iterable.