Skip to content

Instantly share code, notes, and snippets.

@tehpeh
Created May 25, 2011 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tehpeh/990443 to your computer and use it in GitHub Desktop.
Save tehpeh/990443 to your computer and use it in GitHub Desktop.
Sort colours
#!/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