title: Ruby - Compare array element values against other elements
body: <p>Let's say I have an array of objects (or hashes) that looks like the following -</p>
  
  <pre><code>a = [ {salary: 10, products: 1}, {salary: 9, products: 1}, {salary: 10, products: 0} ]
  </code></pre>
  
  <p>I want to remove elements from the array if there exists another element in the array that has a higher product value at the same salary or less. Some pseudo logic to cover those two instances would look like this-</p>
  
  <pre><code>IF EXISTS 'other element' WITH &gt;= products and &lt; salary THEN DELETE
  
  IF EXISTS 'other element' WITH &gt; products and =&lt; salary THEN DELETE
  </code></pre>
  
  <p>What Ruby methods could help me accomplish this?</p>
  
  <p>Edit: In the above example, the expected output would be <code>{salary: 9, products: 1}</code>. The first element should be deleted in the grounds that there's another element with less salary, but the same (or greater) products. The third element could be deleted either on the grounds that the first element has more products at the same salary, or because the 2nd element has more products as less salary.</p>