Skip to content

Instantly share code, notes, and snippets.

@eam
Created June 26, 2013 19:16
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 eam/5870587 to your computer and use it in GitHub Desktop.
Save eam/5870587 to your computer and use it in GitHub Desktop.
>> sort_order = %w{ B E F A C K I M Q D L Z P O }.each_with_index.map { |x,i| [x,i] }.inject({}) { |hash,element| hash[ element[0] ] = element[1]; hash}
=> {"O"=>13, "P"=>12, "Z"=>11, "L"=>10, "D"=>9, "Q"=>8, "M"=>7, "I"=>6, "K"=>5, "C"=>4, "A"=>3, "F"=>2, "E"=>1, "B"=>0}
>> %w{ Z A B C D E }.sort { |a,b| sort_order[a] <=> sort_order[b] } => ["B", "E", "A", "C", "D", "Z"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment