Created
February 15, 2019 19:18
-
-
Save vladimyr/0097eb8fda1049447384d12736ee5555 to your computer and use it in GitHub Desktop.
reduce object
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
config = reduce(argv, (acc, val, key) => { | |
if (key === '_') return acc; | |
return Object.assign(acc, { [key]: val }); | |
}, config); | |
function reduce(obj, callback, initalValue) { | |
return Object.keys(obj).reduce((acc, key) => { | |
return callback(acc, obj[key], key); | |
}, initalValue); | |
} | |
reduce({ test: 12 }, (acc, val, key) => Object.assign(acc, { [key]: val }), { test: 122 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment