title: Remove duplicate objects from array by a certain merge algorithm
body: <p>Here's what I have in mind:</p>
  
  <p>Given an array of objects:</p>
  
  <pre><code>[
      {
          "name": "Kirk",
          "count": 1
      },
      {
          "name": "Spock",
          "count": 1
      },
      {
          "name": "Kirk",
          "count": 1
      }
  ]
  </code></pre>
  
  <p>I am trying to get:</p>
  
  <pre><code>[
      {
          "name": "Kirk",
          "count": 2
      },
      {
          "name": "Spock",
          "count": 1
      }
  ]
  </code></pre>
  
  <p>I am wondering if there's already an algorithm, perhaps combining some higher order functions to achieve this. <strong>I could do this easily with loops, but I am looking for a way to solve it using higher order functions</strong>. If someone could point me to what I should use to achieve this, it would be great. Again, <strong>I'm looking for something as elegant as possible</strong> (two maps and a filter would not be a big improvement from loops).</p>
  
  <p><strong>This is my current solution and I'm looking for something better</strong> (and by better I mean more expressive):</p>
  
  <pre><code>function mergeDuplicates(input) {
    var output = [];
    var existingItem = null;
    input.forEach(function (inputItem) {
      existingItem = _.find(output, function (outputItem) {
        return inputItem.name === outputItem.name;
      });
      existingItem ? existingItem.count += 1 : output.push({
        name: inputItem.name,
        count: 1
      });
      existingItem = null;
    });
    return output;
  }
  </code></pre>
  
  <p>To make line #10 more clear: in the original array, <code>count</code> might be either non-existing or 1, hence I set it to 1.</p>