Mega Code Archive

 
Categories / Ruby / Array
 

Get the bottom 5 elements

l = [1, 60, 21, 100, -5, 20, 60, 22, 85, 91, 4, 66] sorted = l.sort # The bottom 5 p sorted[0...5] # => [-5, 1, 4, 20, 21]