Created
September 3, 2015 19:52
-
-
Save aellispierce/0c5e96315e5d6ff1bfaf to your computer and use it in GitHub Desktop.
mucking around
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
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