I have a 2-d hash.I need to sort each sub-hash by value in descending order.
hsh={"a"=>{0=>1, 1=>2}}
output= {"a"=>{1=>2,0=>1}}
Thanks & Cheers !
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t affect in what order the elements of a hashmap are iterated or displayed (Well in ruby 1.9 iteration (and display) order is guaranteed to be the same as insertion order, so if you create hash from a sorted array, the hash will be sorted as well).
All you can do is turn the hash into an array and sort that. Like: