Let's say I have an array of objects (or hashes) that looks like the following -
a = [ {salary: 10, products: 1}, {salary: 9, products: 1}, {salary: 10, products: 0} ]
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-
IF EXISTS 'other element' WITH >= products and < salary THEN DELETE
IF EXISTS 'other element' WITH > products and =< salary THEN DELETE
What Ruby methods could help me accomplish this?
Edit: In the above example, the expected output would be {salary: 9, products: 1}. 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.
selectorincludeto reference the array inside of the block to see if such a case exists.