apply the sort (or sort!, for in-place changes) : sort « Array « Ruby






apply the sort (or sort!, for in-place changes)


x = [ 2, 5, 1, 7, 23, 99, 14, 27 ]

x.sort! # => [1, 2, 5, 7, 14, 23, 27, 99]

 








Related examples in the same category

1.Get the top 5 elements
2.Get the bottom 5 elements
3.ArgumentError: comparison of Fixnum with String failed
4.Sort object array by object attribute