Actually this would be the Kronecker (or Tensor) Product
Javascript code for the kronecker product of 2 arrays
function kronecker_product(a, b)
{
var i, j, k, al = a.length, bl = b.length, abl = al*bl, ab = new Array(abl);
i = 0; j = 0;
for (k=0; k<abl; k++)
{
if ( j>=bl) {j=0; i++;}
ab[k] = [].concat(a[i],b[j]);
j++;
}
return ab;
}
For disambiguation let me give the code for the cartesian product as well:
function cartesian_product(a, b)
{
var al = a.length, bl = b.length;
return [a.concat(bl>al ? new Array(bl-al) : []), b.concat(al>bl ? new Array(al-bl) : [])];
}
The main difference is the number of components (length) of the final result, in kronecker the length should be the product of the lengths while in cartesian it should be the sum.
Example Kronecker
var a = ["a","b"], b = ["c","d"];
console.log(kronecker_product(a,b));
Output
[["a", "c"], ["a", "d"], ["b", "c"], ["b", "d"]]
Example Cartesian
var a = ["a","b"], b = ["c","d"];
console.log(cartesian_product(a,b));
Output
[["a", "b"], ["c", "d"]]