title: ES6 Sum by object property in an array
body: <p>I am trying to sum the unit value by date, and create a new array where there are no duplicate dates. For example, I want to calculate the total of <code>2015-12-04 00:01:00</code>. This date has occurred 2 times in the following data, its value is <code>5</code> and <code>6</code>, which is going to be:</p>
  
  <pre><code>[{date: '2015-12-04 00:01:00', unit: 11}, ... etc]
  </code></pre>
  
  <p>I have tried <code>arr = results.map(x =&gt; x.unit).reduce((a,c) =&gt; a + c)</code> but it only return a single value, not an array.</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>results = [ { unit: 5, date: '2015-12-04 00:01:00' },
            { unit: 10, date: '2015-12-04 00:01:00' },
            { unit: 5, date: '2015-12-04 00:31:00' },
            { unit: 9, date: '2015-12-04 00:31:00' },
            { unit: 5, date: '2015-12-04 01:01:00' },
            { unit: 10, date: '2015-12-04 01:01:00' },
            { unit: 10, date: '2015-12-04 01:31:00' },
            { unit: 5, date: '2015-12-04 01:31:00' },
            { unit: 10, date: '2015-12-04 02:01:00' },
            { unit: 5, date: '2015-12-04 02:01:00' },
            { unit: 5, date: '2015-12-04 02:31:00' },
            { unit: 9, date: '2015-12-04 02:31:00' },
            { unit: 5, date: '2015-12-04 03:01:00' },
            { unit: 9, date: '2015-12-04 03:01:00' },
            { unit: 5, date: '2015-12-04 03:31:00' },
            { unit: 10, date: '2015-12-04 03:31:00' },
            { unit: 10, date: '2015-12-04 04:01:00' },
            { unit: 5, date: '2015-12-04 04:01:00' }];
  
  arr = results.map(x =&gt; x.unit).reduce((a,c) =&gt; a + c);
  console.log(arr);</code></pre>
  </div>
  </div>
  </p>