say I have an array [["a", "b"], ["c", "d"]] how can I iterate or reduce or map or join this array and get ["ac", "ad", "bc", "bd"] and if array is like [["a", "b"], ["c", "d"], ["e", "f"]] I should get like ["ace", "acf", "ade", "adf", "bce", "bcf", "bde", "bdf"]
how can we achieve this using array iteration or methods?
I tried by using reduce:
const output = [];
const sol = array.reduce((cum, ind) => {
for (let i = 0; i <= cum.length; i++ ) {
for (let j = 0; j <= ind.length; j++) {
output.push(`${cum[i]} + ${ind[j]}`);
}
}
});
console.log(output);
but I didn't get the exact output.
ziplike this, it would be trivial:zip(...inputArray).map(x => x.join()).ziplogic isn't suitable here, because it zips pairs from each array once, it doesn't generate all combinations, which is what the question about.