My goal is to merge 2 arrays in all possible ways, in a way that, the 1st array will always be the first part of the cell, and the 2nd array will always be in the 2nd part of the cell.
My last attempt, which is the closest but not exactly what I need:
function combineArrays(array1, array2) {
let arr = [];
for (let i = 0; i < array1.length; i++) {
arr[i] = array1[i];
}
for (let i = 0, j = 0; i < array1.length; i++) {
arr[i] += array2[j];
if (array2[j + 1]) {
j++;
}
else {
j = 0;
}
}
return arr;
}
Edit:
For example, array A and array B:
A: [ "I", "You", "He", "She" ]
B: [ "am", "is", "are" ]
Expected result:
[
"I am", "You am", "He am", "She am",
"I is", "You is', "He is", "She is",
"I are", "You are", "He are", "She are"
]