Write a method count_letters
that can tell us all the unique characters that exist in a string that is passed into the method. Furthermore, the method should also report back how many instances of each letter were found in the string.
Methods generally return one object. That object can be a number, a boolean, nothing (nil
), a symbol, a string, and so on. However, we need to return an object that can represent all the characters found in the input string, and their respective counts.
What type of object should be returned back by count_letters
? A Hash comes to mind!
So count_letters("lighthouse in the house...")
would return:
{
'l' => 1,