I want to sort my has by value.I am tried to sort my hash this way and it does not work, I don't know why. This is my code:
test="neki text sa recima neki sa i jos neki aa"
mapa=Hash.new(0)
test.split(" ").each do |rec|
mapa[rec]+=1
end
mapa.sort_by {|a,b| b}.reverse
mapa.each do |key, value|
puts "#{key} #{value}"
end
the output is :
neki 3
text 1
sa 2
recima 1
i 1
jos 1
aa 1
It doesn't do anything to the HASH :/ Can someone explain to me why it does not work?
if you give me a MINUS please explain in the comment what I did to deserve it so I know where to improve. :)