Enumerable#max_by
and Enumerable#min_by
return one of the relevant elements (presumably the first one) when there are multiple max/min elements in the receiver. For example, the following:
[1, 2, 3, 5].max_by{|e| e % 3}
returns only 2
(or only 5
).
Instead, I want to return all max/min elements and in an array. In the example above, it would be [2, 5]
(or [5, 2]
). What is the best way to get this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…