Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created February 3, 2014 21:08
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 jonelf/8792448 to your computer and use it in GitHub Desktop.
Save jonelf/8792448 to your computer and use it in GitHub Desktop.
Generic sort order.
sort_order = {"C" => 1, "Y" => 2, "M" => 3}
test_arr = ["M", "C", "Y"]
sorted = test_arr.sort_by {|c| sort_order[c]}
# => ["C", "Y", "M"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment