Skip to content

Instantly share code, notes, and snippets.

@aellispierce
Created September 3, 2015 19:52
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 aellispierce/0c5e96315e5d6ff1bfaf to your computer and use it in GitHub Desktop.
Save aellispierce/0c5e96315e5d6ff1bfaf to your computer and use it in GitHub Desktop.
mucking around
hash = {cool_peaople: 10, bananas: 30, shoes: 20, red: 14}
array = hash.values.sort.reverse
#returns:
# 30
# 20
# 14
# 10
ordered_tuples = Array.new
array.each do |value|
ordered_tuples << {"#{hash.key(value)}" => "#{value }"}
end
puts ordered_tuples
#returns:
# {"bananas"=>"30"}
# {"shoes"=>"20"}
# {"red"=>"14"}
# {"cool_peaople"=>"10"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment