title: Compare objects within an array and create a new array without duplicates
body: <p>I've an array of objects:</p>
  <pre><code>[
    { name: &quot;John&quot;, age: &quot;34&quot; },
    { name: &quot;Ace&quot;, age: &quot;14&quot; },
    { name: &quot;John&quot;, age: &quot;45&quot; },
    { name: &quot;Harry&quot;, age: &quot;11&quot; },
  ]
  </code></pre>
  <p>I want to compare the objects within an array by name. If the duplicate name exists, I should compare the age and only keep the higher age object.</p>
  <p>The expected output should be:</p>
  <pre><code>[
    { name: &quot;Ace&quot;, age: &quot;14&quot; },
    { name: &quot;John&quot;, age: &quot;45&quot; },
    { name: &quot;Harry&quot;, age: &quot;11&quot; },
  ]
  </code></pre>
  <p>I am new to javascript/typescript and couldn't find any optimal solution for this problem. I hope, I was able to explain my problem clearly.</p>
  <p>Thanks.</p>