Last active
July 12, 2018 04:01
-
-
Save maulberto3/fe14535122802a4b76f7c831100231e0 to your computer and use it in GitHub Desktop.
Reduce example #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [["dog", 1], ["cat", 2], ["bear", 3]]; | |
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array | |
const func2 = (obj, prop) => Object.assign(obj, prop); // assigns each object to an accumulator object | |
const obj3 = arr.map(func1).reduce(func2); // nesting | |
console.log(JSON.stringify(obj3, null, 2)); // Prints { "dog": 1, "cat": 2, "bear": 3 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment