A
Amir Ebrahimifard
Hi
Why 2 different sort in below code return different result ?
( I dont understand different between "v1 <=> v2" and "v2 <=> v1" ).
------------------------------------------
array = [3,1,5,2,4]
# => [3, 1, 5, 2, 4]
array.sort {|v1,v2| v1 <=> v2 }
# => [1, 2, 3, 4, 5]
array.sort {|v1,v2| v2 <=> v1 }
# => [5, 4, 3, 2, 1]
Why 2 different sort in below code return different result ?
( I dont understand different between "v1 <=> v2" and "v2 <=> v1" ).
------------------------------------------
array = [3,1,5,2,4]
# => [3, 1, 5, 2, 4]
array.sort {|v1,v2| v1 <=> v2 }
# => [1, 2, 3, 4, 5]
array.sort {|v1,v2| v2 <=> v1 }
# => [5, 4, 3, 2, 1]