diff --git a/README.md b/README.md index 44ffd891e..8e718d097 100644 --- a/README.md +++ b/README.md @@ -280,11 +280,10 @@ const timeTaken = (f,...args) => { ### Object from key-value pairs -Use `map()` to create objects for each key-value pair, combine with `Object.assign()`. +Use `Array.reduce()` to create and combine key-value pairs. ```js -const objectFromPairs = arr => - Object.assign(...arr.map( v => {return {[v[0]] : v[1]};} )); +const objectFromPairs = arr => arr => arr.reduce((a,b) => { a[b[0]] = b[1]; return a;}, {}); ``` ### Powerset diff --git a/snippets/object-from-key-value-pairs.md b/snippets/object-from-key-value-pairs.md index 81cfecaac..0435b4c4d 100644 --- a/snippets/object-from-key-value-pairs.md +++ b/snippets/object-from-key-value-pairs.md @@ -1,8 +1,7 @@ ### Object from key-value pairs -Use `map()` to create objects for each key-value pair, combine with `Object.assign()`. +Use `Array.reduce()` to create and combine key-value pairs. ```js -const objectFromPairs = arr => - Object.assign(...arr.map( v => {return {[v[0]] : v[1]};} )); +const objectFromPairs = arr => arr => arr.reduce((a,b) => { a[b[0]] = b[1]; return a;}, {}); ```