Getting the n Smallest Items of an Array : min « Array « Ruby






Getting the n Smallest Items of an Array


p [3, 5, 11, 16].min                                # => 3
p ["three", "five", "eleven", "sixteen"].min        # => "eleven"
p ["three", "five", "eleven", "sixteen"].min { |x,y| x.size <=> y.size }

 

Related examples in the same category