Project

General

Profile

Actions

Bug #12221

closed

Enumerable#sort_by method doesn't work properly when the array has more than 6 elements and you pass nil to the block

Added by lucascaton (Lucas Caton) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[ruby-core:74603]

Description

%w(1 2).sort_by { |i| nil }
# => ["1", "2"]

# ...

%w(1 2 3 4 5 6).sort_by { |i| nil }
# => ["1", "2", "3", "4", "5", "6"]

So far, so good...
But look what happens when you have 7 or more elements:

%w(1 2 3 4 5 6 7).sort_by { |i| nil }
# => ["4", "2", "3", "1", "5", "6", "7"]

%w(1 2 3 4 5 6 7 8).sort_by { |i| nil }
# => ["8", "2", "3", "4", "5", "6", "7", "1"]

%w(1 2 3 4 5 6 7 8 9).sort_by { |i| nil }
# => ["9", "2", "3", "4", "5", "6", "7", "8", "1"]

%w(1 2 3 4 5 6 7 8 9 10).sort_by { |i| nil }
# => ["10", "2", "3", "4", "5", "6", "7", "8", "9", "1"]
Actions

Also available in: Atom PDF

Like0
Like0Like0