I want to get all the keys with the max value.
# I want 6 and 2 since they both of them occurred three times.
arr = [5, 6, 2, 1, 2, 5, 6, 6, 2]
I tried this but it returns 6 only.
# this returns {5=>2, 6=>3, 2=>3, 1=>1}
freq = hash.inject(Hash.new(0)){ |h, v| h[v] += 1; h }
# then I use max_by, but this gives only 6
p arr.max_by{ |v| freq[v]}