From fab040658bb21f2eac9f5e288cb8eac8df418891 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 24 Jan 2018 15:55:03 +0200 Subject: [PATCH] Add xProd --- snippets/xProd.md | 13 +++++++++++++ tag_database | 1 + 2 files changed, 14 insertions(+) create mode 100644 snippets/xProd.md diff --git a/snippets/xProd.md b/snippets/xProd.md new file mode 100644 index 000000000..332d9f76e --- /dev/null +++ b/snippets/xProd.md @@ -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']] +``` diff --git a/tag_database b/tag_database index c34856405..dbe4c3043 100644 --- a/tag_database +++ b/tag_database @@ -243,6 +243,7 @@ UUIDGeneratorNode:node,utility,random validateNumber:utility,math without:array words:string,regexp +xProd:array,math yesNo:utility,regexp zip:array zipObject:array,object