Hash Sum Method in Ruby
In this guide you will learn how to total the values of a hash instead of overriding it.
Guide Tasks
- Read Tutorial
- Complete the Exercise
Summary
Build out a method that will total the values of a hash.
Exercise Description
"Define a method that will give the total values for a hash instead of overriding it and so that it will skip over an empty hash. "
Example Data
'hash_one = { "Sun, 14 May 2017" => 1 } hash_two = { "Wed, 10 May 2017" => 1, "Thu, 11 May 2017" => 0, "Fri, 12 May 2017" => 0, "Sat, 13 May 2017" => 10, "Sun, 14 May 2017" => 0 } hash_three = { "Thu, 11 May 2017" => 2, "Fri, 12 May 2017" => 0, "Sat, 13 May 2017" => 4, "Sun, 14 May 2017" => 0 } hash_four = { "Fri, 12 May 2017" => 1, "Sat, 13 May 2017" => 1, "Sun, 14 May 2017" => 0 } ' -> expect(hash_sum(hash_one, hash_two, hash_three, hash_four)).to eq( { "Sun, 14 May 2017" => 1, "Wed, 10 May 2017" => 1, "Thu, 11 May 2017" => 2, "Fri, 12 May 2017" => 1, "Sat, 13 May 2017" => 15 } )
Real World Usage
This exercise will help you be able to give the total values for hashes instead of having to override them.