var dmg1 = {
"nick1": 100,
"nick2": 50
}
var dmg2 = {
"nick1":50,
"nick2":150
}
var dmg3 = {
"nick1":150,
"nick2":150
}
const sum = (...arr) => arr
.flatMap(Object.entries)
.reduce((acc, [ k, v ]) => (
acc[k] = (acc[k] ?? 0) + v,
acc
), {});
function sum() {
const result = {};
for (const n of arguments) {
for (const k in n) {
if (n.hasOwnProperty(k)) {
if (!result.hasOwnProperty(k)) {
result[k] = 0;
}
result[k] += n[k];
}
}
}
return result;
}
const obj = sum(obj1, obj2);
.