Question : sort numbers in ascending order ruby
Answered by : stephen-nwankwo
result = [41, 9, -9, 2, 31, 32, 12, -1]
result = result.sort { |a, b| a <=> b }
puts result
#OUTPUT:
-9
-1
2
9
12
31
32
41
Source : | Last Update : Tue, 23 Aug 22
Question : ruby sort array numerically
Answered by : beautiful-bear-jwxgx4frys32
a.sort_by(&:to_i)
Source : https://stackoverflow.com/questions/7726968/sort-an-array-of-strings-by-their-integer-values/7727416 | Last Update : Tue, 22 Dec 20
Question : ruby sort array numerically
Answered by : beautiful-bear-jwxgx4frys32
a = ["teste", "test", "teste2", "tes3te", "10teste"]
a.sort_by! {|s| s[/\d+/].to_i}
Source : https://stackoverflow.com/questions/7726968/sort-an-array-of-strings-by-their-integer-values/7727416 | Last Update : Tue, 22 Dec 20