Actions
Bug #16966
closedUnexpected behavior of sort method
Bug #16966:
Unexpected behavior of sort method
Description
The ruby cook book from 2015 has the following example of using sort
method:
[1,100,42,23,26,1000].sort {|x,y| x==42 ? 1 : x<=>y }
# => [1, 23, 26, 100, 10000, 42]
It actually returned [1, 23, 26, 42, 100, 1000]
.
With a different array, I get the expected result with 42 at the end:
[1,2,42,46,22,33].sort {|x,y| x==42 ? 1 : x<=>y }
# => [1, 2, 22, 33, 46, 42]
Files
Actions