logo CodeStepByStep logo

least_common

Language/Type: Perl collections hash

Write a subroutine named least_common that accepts as a parameter a hash whose keys are strings and whose values are integers and returns the integer value that occurs the fewest times in the hash. For example, if a hash named %ages contains ("Alyssa" => 22, "Char" => 25, "Dan" => 25, "Jeff" => 20, "Kasey" => 20, "Kim" => 20, "Mogran" => 25, "Ryan" => 25, "Stef" => 22), the call of least_common(%ages) returns 22. If there is a tie, return the smaller integer value. If the map is empty, return 0.

Function: Write a Perl function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.