From 6c47aae3b055fa892e0d1179edca2b340694a341 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 14:55:18 -0800 Subject: [PATCH 01/10] Create zipObject.md Will also need to add a tag in the tag database --- snippets/zipObject.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 snippets/zipObject.md diff --git a/snippets/zipObject.md b/snippets/zipObject.md new file mode 100644 index 000000000..169cdaeb1 --- /dev/null +++ b/snippets/zipObject.md @@ -0,0 +1,11 @@ +### zipObject + +Given an Array of valid property identifiers and an Array of values, `zipObject` returns an object mapping the properties to the values +Since an object can have undefined values but not undefined property pointers, the Array of properties is used to decide the structure of the resulting object + +```js +const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) +/* +zipObject(['a','b','c'], [1,2]) +*/ +``` From 627e5f422578bb27cc7f6b6c991fe0a8a5c11da1 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 14:56:03 -0800 Subject: [PATCH 02/10] Update tag_database with zipObject --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index f3ad1b365..a0a06d2d0 100644 --- a/tag_database +++ b/tag_database @@ -118,3 +118,4 @@ validateEmail:utility validateNumber:utility without:array zip:array +zipObject:array From 8cf6092e141ddfae698e36eaf96ab401ecb212e4 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 14:57:20 -0800 Subject: [PATCH 03/10] Update zipObject.md --- snippets/zipObject.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index 169cdaeb1..b37e04045 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -6,6 +6,6 @@ Since an object can have undefined values but not undefined property pointers, t ```js const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) /* -zipObject(['a','b','c'], [1,2]) +zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} */ ``` From e194269da924bb196dfbfd5969853d5759191275 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 14:59:23 -0800 Subject: [PATCH 04/10] Update zipObject.md --- snippets/zipObject.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index b37e04045..ca1174bee 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -1,7 +1,8 @@ ### zipObject -Given an Array of valid property identifiers and an Array of values, `zipObject` returns an object mapping the properties to the values -Since an object can have undefined values but not undefined property pointers, the Array of properties is used to decide the structure of the resulting object +Given an Array of valid property identifiers and an Array of values, `zipObject` returns an object associating the properties to the values + +Since an object can have undefined values but not undefined property pointers, the Array of properties is used to decide the structure of the resulting object through a `reduce` ```js const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) From 48c2625e16508dcb405e03dc7c0203ab81a92a3e Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 15:02:43 -0800 Subject: [PATCH 05/10] Update zipObject.md --- snippets/zipObject.md | 1 + 1 file changed, 1 insertion(+) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index ca1174bee..bc9ecc010 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -8,5 +8,6 @@ Since an object can have undefined values but not undefined property pointers, t const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) /* zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} +zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} */ ``` From 8554fa507a6a76e1df39e6456aba846a18f90300 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 15:03:40 -0800 Subject: [PATCH 06/10] Update zipObject.md --- snippets/zipObject.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index bc9ecc010..ab8ac6ee5 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -5,7 +5,7 @@ Given an Array of valid property identifiers and an Array of values, `zipObject` Since an object can have undefined values but not undefined property pointers, the Array of properties is used to decide the structure of the resulting object through a `reduce` ```js -const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) +const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} ) /* zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} From 2c5f6261ea0275ca885605362a0331d2b8aac0a4 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 15:04:32 -0800 Subject: [PATCH 07/10] Update zipObject.md --- snippets/zipObject.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index ab8ac6ee5..3bf6bee60 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -6,8 +6,7 @@ Since an object can have undefined values but not undefined property pointers, t ```js const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} ) -/* -zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} -zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} -*/ +// zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} +// zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} + ``` From 3ae52f466f600894ca2e190cb098478def49f0cd Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 16:18:57 -0800 Subject: [PATCH 08/10] Update zipObject.md --- snippets/zipObject.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index 3bf6bee60..d1f8b9e32 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -1,8 +1,8 @@ ### zipObject -Given an Array of valid property identifiers and an Array of values, `zipObject` returns an object associating the properties to the values +Given an array of valid property identifiers and an array of values, `zipObject` returns an object associating the properties to the values -Since an object can have undefined values but not undefined property pointers, the Array of properties is used to decide the structure of the resulting object through a `reduce` +Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object through a `reduce` ```js const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} ) From bbf3fc5fa3cf46fc3e1e870d15d3b191c3a0321f Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Wed, 20 Dec 2017 16:19:12 -0800 Subject: [PATCH 09/10] Update zipObject.md --- snippets/zipObject.md | 1 - 1 file changed, 1 deletion(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index d1f8b9e32..a698038b9 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -8,5 +8,4 @@ Since an object can have undefined values but not undefined property pointers, t const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} ) // zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} // zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} - ``` From 07c5ee65d8b12faef54c51d065efcf660a6b9dd8 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 21 Dec 2017 11:13:38 +0200 Subject: [PATCH 10/10] Update zipObject.md --- snippets/zipObject.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/zipObject.md b/snippets/zipObject.md index a698038b9..f9214e7aa 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -1,8 +1,8 @@ ### zipObject -Given an array of valid property identifiers and an array of values, `zipObject` returns an object associating the properties to the values +Given an array of valid property identifiers and an array of values, return an object associating the properties to the values. -Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object through a `reduce` +Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object using `Array.reduce()`. ```js const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} )