diff --git a/README.md b/README.md index 8e718d097..2c6e2082c 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ const timeTaken = (f,...args) => { Use `Array.reduce()` to create and combine key-value pairs. ```js -const objectFromPairs = arr => arr => arr.reduce((a,b) => { a[b[0]] = b[1]; return a;}, {}); +const objectFromPairs = arr => arr => arr.reduce((a,b) => (a[b[0]] = b[1], a), {}); ``` ### Powerset diff --git a/snippets/object-from-key-value-pairs.md b/snippets/object-from-key-value-pairs.md index 0435b4c4d..90f41802c 100644 --- a/snippets/object-from-key-value-pairs.md +++ b/snippets/object-from-key-value-pairs.md @@ -3,5 +3,5 @@ Use `Array.reduce()` to create and combine key-value pairs. ```js -const objectFromPairs = arr => arr => arr.reduce((a,b) => { a[b[0]] = b[1]; return a;}, {}); +const objectFromPairs = arr => arr => arr.reduce((a,b) => (a[b[0]] = b[1], a), {}); ```