Created
December 27, 2010 15:39
-
-
Save iNecas/756222 to your computer and use it in GitHub Desktop.
Ordering major.minor.revision version numbers
This file contains hidden or 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
# wrong | |
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort | |
# => ["10.1.1", "9.13.3", "9.3.2", "9.3.5"] | |
# right | |
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort_by{|version| version.scan(/\d+/).map(&:to_i)} | |
# => ["9.3.2", "9.3.5", "9.13.3", "10.1.1"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment