I have an array [1,2,4,5,4,7] and I want to find the frequency of each number and store it in a hash. I have this code, but it returns NoMethodError: undefine
[1,2,4,5,4,7]
NoMethodError: undefine
In Ruby 2.4+:
def score(array) array.group_by(&:itself).transform_values!(&:size) end