Hackerrank Day 0: Means, Median, Mode

screen-shot-2016-12-28-at-2-27-26-pm

My Solution in Ruby: 

screen-shot-2016-12-28-at-2-26-37-pm

This was a good review on arrays and hashes.

  • Find the sum of all elements in an array with: array.inject(0){|sum, x| sum + x}
  • Store number of occurrences in hashes so you can retrieve key-value pairs based on its value or key attributes.
  • String can be converted to array with .split(‘ ‘).map(&:to_i).
Advertisements
Hackerrank Day 0: Means, Median, Mode

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