From 1f5585c385e7bcf8423683f611377f354153f34d 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 4fb1235fd416a34aa897402f61a08b602a3fdb42 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 5542916fdeffcee173ec5023da4f5873ad0b0a6e 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 4e1abfcff66684d245ba29cc218546ad7ca7d932 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 651547c3f92332f2e0598f1794516896c06fb598 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 52902ad97a0733a046af5ad519c68d0934cde4f7 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 c235295b5b8f64d4b83181ac31b5c92665c4620c 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 4b697e63512989eeac9a1da0160a9a7fd7f9adcb 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 3cf7ce01188b878f7da02701ede476f2e7772cba 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 2f1193915eac6b50c0eb457840bb8af0e783ab21 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 ), {} )