Q:

Write a JavaScript program to create a new array out of the two supplied by creating each possible pair from the arrays

0

Write a JavaScript program to create a new array out of the two supplied by creating each possible pair from the arrays.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []);
console.log(xProd([1, 2], ['a', 'b']));
console.log(xProd([1, 2], [1, 2]));
console.log(xProd(['a', 'b'], ['a', 'b']));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now