mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-12-08 19:06:00 +00:00
16 lines
359 B
JavaScript
16 lines
359 B
JavaScript
export default function cartesianProduct(setA, setB) {
|
|
if (!setA || !setB || !setA.length || !setB.length) {
|
|
return null;
|
|
}
|
|
|
|
const product = [];
|
|
|
|
for (let indexA = 0; indexA < setA.length; indexA += 1) {
|
|
for (let indexB = 0; indexB < setB.length; indexB += 1) {
|
|
product.push([setA[indexA], setB[indexB]]);
|
|
}
|
|
}
|
|
|
|
return product;
|
|
}
|