Created
May 25, 2011 06:15
-
-
Save tehpeh/990443 to your computer and use it in GitHub Desktop.
Sort colours
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
#!/usr/bin/env ruby | |
def sort_colours(str) | |
ranking = { | |
"blue" => 1, | |
"orange" => 2, | |
"green" => 3, | |
"yellow" => 4, | |
"pink" => 5, | |
"red" => 6, | |
"grey" => 7, | |
"lime" => 8 | |
} | |
str.split.sort do |a,b| | |
ranking[a] <=> ranking[b] | |
end | |
end | |
puts sort_colours(%q[orange yellow lime grey pink blue green red]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment