I have one array of hashes as following:
[{"k1"=>"v1", "k2"=>"75.1%"}, {"k1"=>"v2", "k2"=>"-NA-"}, {"k1"=>"v3", "k2"=>"5.1%"}]
I want to sort this array of hashes based on the value of key "k2"
. I want to sort it in the decreasing order with "-NA-"
coming at top always.
I want sorted array like this:
[{"k1"=>"v2", "k2"=>"-NA-"}, {"k1"=>"v1", "k2"=>"75.1%"}, {"k1"=>"v3", "k2"=>"5.1%"}]
I tried hash.sort_by method, but got incorrect results. How to do it in Ruby?