My input hash: h = { "a" => 20, "b" => 30, "c" => 10 }
Ascending sort: h.sort {|a,b| a[1]<=>b[1]} #=> [["c", 10], ["a", 20], ["b", 30]]
But, I need [["b", 30], ["a", 20], ["c", 10]]
How is can we make it work the other way around, what does <=>
mean?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…