Skip to content

Home

Cross product of arrays

Creates a new array out of the two supplied by creating each possible pair from the arrays.

const xProd = (a, b) =>
  a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []);

xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

More like this

Start typing a keyphrase to see matching snippets.