I am given 2 arrays , each of them has 10 elements each as shown below: [A1, B1, C1, D1, E1, F1, G1, H1, I1, J1] and [A2, B2, C2, D2, E2, F2, G2, H2, I2, J2]
I am expected to do the following:
list all possible combinations of the elements of the first two arrays making sure that the occurence of an element of the same index does not occur per output ie A1 and A2 should not be appear on same output same as B1 and B2 etc
Hint: Output should look like this: [
[A1, B1, C1, D1, E1, F1, G1, H1, I1, J1]
[A2, B2, C2, D2, E2, F2, G2, H2, I2, J2]
[A1, B2, C2, D2, E2, F2, G2, H2, I2, J2]
[A2, B1, C1, D1, E1, F1, G1, H1, I1, J1]
[A1, B1, C1, D1, E1, F1, G1, H1, I1, J2]
...
...
...
[A1, B1, C2, D2, E2, F2, G2, H2, I2, J2]
[A1, B1, C1, D2, E1, F1, G1, H1, I1, J2]
[A1, B1, C1, D1, E2, F1, G1, H1, I1, J2]
...
...
...
]
There are supposed to be 1024 outputs in all
i need help to achieve the above output in Javascript
below is waht I have tried:
function combineLatest1(arrFirst,arrSecond){
let newArr = [[...arrFirst],[...arrSecond]]; // make copies of the original arrays since they are valid output
// perform the looping over the two arrays
arrFirst.shift();
let tempAr = [...arrFirst];
arrSecond.forEach(function(item){
if(!tempAr.includes(item)){
tempAr.push(item);
}
newArr.push(tempAr);
});
return newArr;
}