Find The Min And Max With A Single Call
Ruby's Enumerable comes with the #min
and #max
methods for finding, respectively, the minimum and maximum value in the target collection.
If you wanted to find both the min and the max of the same collection, you could call them one after another.
Ruby's Enumerable also supports a slightly more efficient way -- it finds both at the same time when you call #minmax
.
Last updated