Last active
March 5, 2020 15:16
-
-
Save lluisruscalleda/5c035d13972a7a33b5e555018e0da763 to your computer and use it in GitHub Desktop.
Sum values from an array of objects with the same keys in javascript
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
export const sumObjs = (...objs) => Object.assign({}, | |
...objs.reduce((acc, obj) => Object.keys(obj).map((key) => { | |
const ret = {}; ret[key] = acc[key] + obj[key]; | |
return ret; | |
}))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment