Sorting an Array of Hashes with unknown keys
Jul 19
2008
2008
Comments Off
AoH = [{"z"=>26}, {"g"=>7}, {"r"=>18}, {"a"=>1}, {"v"=>22}] # sort by key AoH.map{|e| e.to_a.flatten}.sort{|x,y| x[0] < => y[0]} # sort by value AoH.map{|e| e.to_a.flatten}.sort{|x,y| x[1] < => y[1]}