Last active
April 12, 2016 12:01
-
-
Save lucascaton/af44fc82e0b11a842874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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"] | |
# 🤔 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Weird!
What's the difference?