Most common letter

Write a method that takes in a string. Your method should return the most common letter in the array, and a count of how many times it appears.

Solution:

screen-shot-2016-09-15-at-1-59-07-pm

Hash.new 0 sets up an empty hash.  { }

counts.max_by return the max key-value pair based on the value of “v”.

Alternative solution:

Screen Shot 2016-08-17 at 9.29.28 PM

Provided solution:

screen-shot-2016-09-15-at-2-13-53-pm

Third time doing this, I just used a hash.  Not sure if I’m using the max function correctly here:

screen-shot-2016-11-04-at-3-45-18-pm

Advertisements
Most common letter

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s