Letter Count

Write a function, ‘letter_count(str)’ that takes a string and
returns a hash mapping each letter to its frequency. Do not include

Test Cases:


My Solution:


Runtime:  0.00059 seconds

Provided Solution:

Screen Shot 2016-11-21 at 12.38.20 PM.png

Runtime:  0.00053 seconds

By using each_char (an enumerator), you’re able to skip splitting the string into words and then into letters. Instead, you can directly pull letters from the string as is.

Letter Count

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s