Add xProd
This commit is contained in:
13
snippets/xProd.md
Normal file
13
snippets/xProd.md
Normal 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']]
|
||||||
|
```
|
||||||
@ -243,6 +243,7 @@ UUIDGeneratorNode:node,utility,random
|
|||||||
validateNumber:utility,math
|
validateNumber:utility,math
|
||||||
without:array
|
without:array
|
||||||
words:string,regexp
|
words:string,regexp
|
||||||
|
xProd:array,math
|
||||||
yesNo:utility,regexp
|
yesNo:utility,regexp
|
||||||
zip:array
|
zip:array
|
||||||
zipObject:array,object
|
zipObject:array,object
|
||||||
|
|||||||
Reference in New Issue
Block a user