mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
### What does this PR do? Fixes https://github.com/oven-sh/bun/issues/24385 ### How did you verify your code works? Confirmed that the test added in the first commit fails on mainline `bun` and is fixed in this PR. --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
12 lines
404 B
TypeScript
12 lines
404 B
TypeScript
/**
|
|
* Computes the Cartesian product of multiple arrays.
|
|
*
|
|
* @param arrays An array of arrays for which to compute the Cartesian product.
|
|
* @returns An array containing all combinations of elements from the input arrays.
|
|
*/
|
|
export function cartesianProduct<T, U>(left: T[], right: U[]): [T, U][] {
|
|
return left.flatMap(leftItem =>
|
|
right.map(rightItem => [leftItem, rightItem] as [T, U])
|
|
);
|
|
}
|