我有一个这样的数组:
["Is", "Gandalf", "The", "Gray", "Insane"]
我想根据数组中键的位置对哈希进行排序。例如,我想排序:
{:count=>21, "Is"=>19, "Gandalf"=>1, "Gray"=>0, "Insane"=>1, "The"=>5}
进入这个:
{"Is"=>19, "Gandalf"=>1, "The"=>5, "Gray"=>0, "Insane"=>1, :count=>21}
另一个例子是排序:
{:count=>3, "Is"=>11, "Insane"=>22, "Gray"=>0, "Gandalf"=>12, "The"=>2}
进入这个:
{"Is"=>11, "Gandalf"=>12, "The"=>2, "Gray"=>12, "Insane"=>22, :count=>3}
如何做到这一点?