Answers for "javascript es6 filter sum distinct"

0

javascript es6 filter sum distinct

const arr = [ { 'name': 'P1', 'value': 150 }, { 'name': 'P1', 'value': 150 }, { 'name': 'P2', 'value': 200 }, { 'name': 'P3', 'value': 450 } ];

const res = Array.from(arr.reduce(
  (m, {name, value}) => m.set(name, (m.get(name) || 0) + value), new Map
), ([name, value]) => ({name, value}));
console.log(res);
Posted by: Guest on August-23-2021

Code answers related to "javascript es6 filter sum distinct"

Code answers related to "Javascript"

Browse Popular Code Answers by Language