Ruby has Enumerable#max and Enumerable#max_by and I am using max_by in the following way.
array = [
{:a => 1, :b => 2, :c => 3},
{:a => 3, :b => 2, :c => 4},
{:a => 3, :b => 1, :c => 4}
]
max_item = array.max_by { |item| item[:b] }
=> {:b=>2, :c=>3, :a=>1}
So, it will return a single maximum (I think first), even though there are 2 items with same maximum value. I want to implement a function which gives both the items in such cases. Is there some other variant of max_by or do I need to write from scratch for this?
group_byworks a little too hard, but it does deliver.