title: Javascript - Counting duplicates in array of object with many fields in es6
body: <p>I have object array like this. </p>
  
  <pre><code>const array = [ { x: 1, y: 2 }, { x: 3, y: 4 }, { x: 1, y: 2 }, { x: 3, y: 4 }, { x: 1, y: 2 }, { x: 3, y: 12 } ]
  </code></pre>
  
  <p>I want to count duplicates objects and store the count as new object field. </p>
  
  <p>I found this snippet and it work great but it not exactly what i need. </p>
  
  <pre><code>const names = [{  _id: 1 }, { _id: 1}, { _id: 2}, { _id: 1}]
  
      const result = [...names.reduce( (mp, o) =&gt; {
      if (!mp.has(o._id)) mp.set(o._id, Object.assign({ count: 0 }, o));
      mp.get(o._id).count++;
      return mp;
      }, new Map).values()];
  
      console.log(result);
  </code></pre>
  
  <p>It works with object with one field _id. In my case there are two, x and y</p>
  
  <p>How should I modify that code?</p>
  
  <p>In brief...I would like to receive the result:</p>
  
  <pre><code>result = [ { x: 1, y: 2, count:3 }, { x: 3, y: 4, count:2 }, { x: 3, y: 12, count:1 } ]
  </code></pre>