Question: look at the hash_2_array method in the lib/hashes.rb file. You will notice that this method takes one input. contacts: a hash for contacts. The keys
look at the hash_2_array method in the lib/hashes.rb file. You will notice that this method takes one input. contacts: a hash for contacts. The keys for this hash will be the contact names as type string and the values will be an inner hash that will hold the email address (with "email" as key) as type string and phone number (with "phone" as key) as type string. Example: {:"Bob Smith"=>{:email=>"bobsmith@example.com", :phone=>"555-555-5555"} Hint: Look at the rspec tests to see the input that will be tested and the expected output.
Write the Ruby code in this method that will create three arrays of type string from the hash and then will return an array that contains the these three arrays (a two dimensional array!). Assumption: Your returned array will contain the inner arrays in the following order: emails, phones, names. Example: [["bobsmith@example.com"],["555-555-5555"],["Bob Smith"]] Run rspec in the terminal window to test. Once everything is passing, upload your screenshot to this question.
hashes_spec.rb
describe 'Ruby Hashes Part III' do
describe "hash_2_array", :disabled => true do it "should be defined" do expect { hash_2_array({:"Bob Smith"=>{:email=>"bobsmith@example.com", :phone=>"555-555-5555"}, :"Sally Field"=>{:email=>"sallyfield@example.com", :phone=>"111-111-1111"}}) }.not_to raise_error end it "returns the correct array of arrays [20 points]" , points: 20 do expect(hash_2_array({:"Bob Smith"=>{:email=>"bobsmith@example.com", :phone=>"555-555-5555"}, :"Sally Field"=>{:email=>"sallyfield@example.com", :phone=>"111-111-1111"}})).to be_a_kind_of Array expect(hash_2_array({:"Bob Smith"=>{:email=>"bobsmith@example.com", :phone=>"555-555-5555"}, :"Sally Field"=>{:email=>"sallyfield@example.com", :phone=>"111-111-1111"}})).to eq([["bobsmith@example.com","sallyfield@example.com"],["555-555-5555","111-111-1111"],["Bob Smith","Sally Field"]]) end it "works on the empty hash [10 points]" , points: 10 do expect { hash_2_array({}) }.not_to raise_error expect(hash_2_array({})).to eq([[],[],[]]) end end end
hashes.rb
# Part III def hash_2_array contacts # YOUR CODE HERE end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
