title: How to loop through array of objects and accumulate a value based on a separate matching value
body: <p>Given I have the following array of objects:</p>
  <pre><code>const data = [
   {
     name: 'item1',
     score: 5,
     colour: 'red'
   },
   {
     name: 'item2',
     score: 5,
     colour: 'blue'
   },
   {
     name: 'item1',
     score: 5,
     colour: 'blue'
   },
   {
     name: 'item3',
     score: 15,
     colour: 'blue'
   },
   {
     name: 'item2',
     score: 25,
     colour: 'green'
   }
  ]
  </code></pre>
  <p>I'm looking for the most semantic approach to looping through this and accumulating the <em>score</em>, given the <em>name</em> value is a match - example result (we don't care about the <em>colour</em> key):</p>
  <pre><code>[
   {
    name: item1,
    score: 10
   },
   {
    name: item2,
    score: 30
   },
   {
    name: item3,
    score: 15
   }
  ]
  </code></pre>
  <p>The final order isn't of importance, but the data will be generated randomly by site visitors (so we have no prior knowledge of each <em>name</em> for example) there could be 2 entries or a maximum of 15.</p>
  <p>Right now, I am solving this with what feels like a long winded (Sunday evening!) approach:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const data = [
   {
     name: 'item1',
     score: 5,
     colour: 'red'
   },
   {
     name: 'item2',
     score: 5,
     colour: 'blue'
   },
   {
     name: 'item1',
     score: 5,
     colour: 'blue'
   },
   {
     name: 'item3',
     score: 15,
     colour: 'blue'
   },
   {
     name: 'item2',
     score: 25,
     colour: 'green'
   }
  ];
  
  let scoreData;
  
  const checkScore = (data) =&gt; {
          // check to see if we have existing data, if not create new array and pass in our initial data
          if (!scoreData) {
             scoreData = [];
             scoreData.push(data);
          }
  
          // check to see if name is already present in our data, if so, accumulate the score
          else if (scoreData.filter(e =&gt; e.name === data.name).length &gt; 0) {
              scoreData
                  .filter(e =&gt; e.name === data.name)
                  .map(e =&gt; e.score += data.score)
          } else {
              scoreData.push(data)
          }
  }
  
  for (let i = 0; i &lt; data.length; i++) {
      
     // save data to new object to compare
     let dataObj = {
           name: data[i].name,
           score: Number(data[i].score)
      }
      
      checkScore(dataObj)
  }
  console.log(scoreData)</code></pre>
  </div>
  </div>
  </p>
  <p>My gut says there's a cleaner approach here and I would love to find one! Greatly appreciate any feedback. Apologies for the poor title, also!</p>