I have a challenge where I need to take two arrays (which are arrays of integers) and create nested objects using the "Cartesian Product" in both directions. I am considering whether this is more of a permutation problem and suspect that it may involve utilizing methods on the array prototype. Here's an example to illustrate:
const firstArray = [1, 2, 3];
const secondArray = [4, 5, 6];
function generateCartesianProduct(firstArray, secondArray) {
// logic goes here
}
console.log(generateCartesianProduct(firstArray, secondArray))
// expected output
{
"firstWay": {
"1": {
"4": true,
"5": true,
"6": true
},
"2": {
"4": true,
"5": true,
"6": true
},
"3": {
"4": true,
"5": true,
"6": true
}
},
"secondWay": {
"4": {
"1": true,
"2": true,
"3": true
},
"5": {
"1": true,
"2": true,
"3": true
},
"6": {
"1": true,
"2": true,
"3": true
}
}
}