Add xProd

This commit is contained in:
Angelos Chalaris
2018-01-24 15:55:03 +02:00
parent e141cce683
commit 04e667b367
2 changed files with 14 additions and 0 deletions

13
snippets/xProd.md Normal file
View File

@ -0,0 +1,13 @@
### xProd
Creates a new array out of the two supplied by creating each possible pair from the arrays.
Use `Array.map()` to produce every possible pair from the elements of the two arrays.
```js
const xProd = (a, b) => a.map(x => b.map(y => [x, y]));
```
```js
xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
```