[
{ id: '235540633', duration: 163 },
{ id: '222333444', duration: 100 },
{ id: '112233445', duration: 31 },
{ id: '112233445', duration: 63 }
]
[
{ id: '235540633', duration: 163 },
{ id: '222333444', duration: 100 },
{ id: '112233445', duration: 94 }
]
const uniqueWithSum = (arr, idKey, sumKey) =>
Object.values(arr.reduce((acc, n) => {
const id = n[idKey];
acc[id] = acc[id] || Object.assign(new n.constructor, n, { [sumKey]: 0 });
acc[id][sumKey] += n[sumKey];
return acc;
}, {}));
// ваш случай
const result = uniqueWithSum(arr, 'id', 'duration');
// элементам не обязательно быть объектами, это могут быть и массивы
uniqueWithSum([
[ 'A', 1 ],
[ 'B', 5 ],
[ 'A', 2 ],
[ 'A', 3 ],
], 0, 1) // [ [ 'A', 6 ], [ 'B', 5 ] ]