+ 2

About sort method

I want to know why following 2 ways to use sort method can reverse the elements in the array "a". a = (1..100).to_a (1) a2 = a.sort{|n1, n2| n2 <=> n1 } p a2 (2) a3 = a.sort_by{|i| -i } p a3 Thank u for ur helping.

15th Jan 2019, 2:58 AM
Yuta Shimizu
Yuta Shimizu - avatar
1 Resposta
+ 2
start with shell and bubble sort algoritms
17th Jan 2019, 10:30 AM
Da2
Da2 - avatar