Count values in hash

Problem

  • Create a method that will count the values of a hash.

Solution

hash = {a: 5, b: 2, c: 3, d: 5}

def value_count(hash, value)
  hash.values.count(value)
end
  • Setup a method that takes two arguments (hash and value).
  • Get the values of the hash using the values method.
  • This method returns an array which is convenient beacause we can then use count method.
  • We then give it an argument to only return counts for the value provided.