title: lodash - Count duplicate and then remove them
body: <p>I am trying to use lodash to first count how many duplicates are in an array of objects and the remove the duplicate (keeping the counter).</p>
  
  <p>The code I have so far seem to work, but I canìt figure out how to merge the two (sorry, new with lodash).</p>
  
  <p>Here's some code:</p>
  
  <pre><code>var array = [
  {id: 1, name: "test"},
  {id: 2, name: "test 2"},
  {id: 3, name: "test 3"},
  {id: 4, name: "test 4"},
  {id: 1, name: "test "},
  {id: 2, name: "test 2"},
  ]
  
  // This finds the duplicates and removes them
  result = _.uniqBy(array, 'id')
  
  // this counts how many duplicates are in the array
  count = _(result)
  .groupBy('id')
  .map((items, name) =&gt; ({ name, count: items.length }))
  .value();
  </code></pre>
  
  <p>I would like to count, then remove but keep the count, so that the final result basically tells me how many products are in the order, but keeping the same together and changing the quantity from 1 to 2.</p>
  
  <p>I did try with this, but it doesn't work:</p>
  
  <pre><code>result = _(result)
    .groupBy('id')
    .map((items, name) =&gt; ({ name, count: items.length }))
    .uniqBy(result, 'name')
    .value()
  </code></pre>
  
  <p>which will give me something like this:</p>
  
  <pre><code>result = [
  {id: 1, name: "test", qty: 2},
  {id: 2, name: "test 2", qty: 2},
  {id: 3, name: "test 3", qty: 1},
  {id: 4, name: "test 4", qty: 1}
  ]
  </code></pre>
  
  <p>Any help?</p>
  
  <p>Thanks</p>