title: Remove duplicates objects from array by name and max category
body: <p>How should I remove duplicate objects with the condition?</p>
  <p>suppose I have this array :</p>
  <pre><code>let my_array = [
    { name: &quot;foo&quot;, version: &quot;10&quot; },
    { name: &quot;foo&quot;, version: &quot;60&quot; },
    { name: &quot;foo&quot;, version: &quot;20&quot; },
    { name: &quot;bar&quot;, version: &quot;400&quot; },
  ];
  </code></pre>
  <p>I need to keep the object that has latest version in it from duplicates.</p>
  <p>I know I can use Set for removing dups :</p>
  <pre><code>let unique = my_array.filter((set =&gt; f =&gt;
      !set.has(f.name) &amp;&amp; set.add(f.name)
    )
    (new Set)
  )
  </code></pre>
  <p>the expected result with condition of max version is :</p>
  <pre><code>let my_array = [
    { name: &quot;foo&quot;, version: &quot;60&quot; },
    { name: &quot;bar&quot;, version: &quot;400&quot; },
  ];
  </code></pre>