Skip to content

Instantly share code, notes, and snippets.

@vladimyr
Created February 15, 2019 19:18
Show Gist options
  • Save vladimyr/0097eb8fda1049447384d12736ee5555 to your computer and use it in GitHub Desktop.
Save vladimyr/0097eb8fda1049447384d12736ee5555 to your computer and use it in GitHub Desktop.
reduce object
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