title: Group + sum with Javascript, Underscore or Lodash
body: <p>I am wondering how I could perform the following grouping and summing up with Underscore or Lodash.</p>
  
  <blockquote>
    <p><strong>MY ARRAY :</strong></p>
  </blockquote>
  
  <pre><code>[
  {_id : "1", S : "2"},
  {_id : "1", M : "4"},
  {_id : "2", M : "1"},
  {_id : "" , M : "1"},
  {_id : "3", S : "3"}
  ]
  </code></pre>
  
  <blockquote>
    <p><strong>DESIRED OUTPUT</strong></p>
  </blockquote>
  
  <pre><code>[
  {_id : "1", M : "4", S : "2", Total: "6"},
  {_id : "2", M : "1", S : "0", Total: "1"},
  {_id : "3", M : "0", S : "3", Total: "3"},
  {_id : "",  M : "1", S : "0", Total: "1"}
  ]
  </code></pre>
  
  <blockquote>
    <p>What I have this far</p>
  </blockquote>
  
  <p>I have a strong believe that I have done the following right this far, but I cannot figure out what I have put in ??</p>
  
  <pre><code>var groups = _.groupBy(MyArray, function(value){
              return value._id;
          });
  
          var data = _.map(groups, function(group){
              return {
                  _id: group[0]._id,
                  M:  ?? ,
                  S:  ?? ,
                  T:  ?? 
  
              }
          });
  </code></pre>