Last active
August 29, 2015 14:26
-
-
Save blake41/0f3113b4f9bb1fe1b3bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
def second_supply_for_fourth_of_july(holiday_hash) | |
# given that holiday_hash looks like this: | |
# { | |
# :winter => { | |
# :christmas => ["Lights", "Wreath"], | |
# :new_years => ["Party Hats"] | |
# }, | |
# :summer => { | |
# :fourth_of_july => ["Fireworks", "BBQ"] | |
# }, | |
# :fall => { | |
# :thanksgiving => ["Turkey"] | |
# }, | |
# :spring => { | |
# :memorial_day => ["BBQ"] | |
# } | |
# } | |
# return the second element in the 4th of July array | |
holiday_hash[:summer][:fourth_of_july][1] | |
end | |
def add_supply_to_winter_holidays(holiday_hash, supply) | |
# holiday_hash is identical to the one above | |
# add the second argument, which is a supply, to BOTH the | |
# Christmas AND the New Year's arrays | |
# holiday_hash[:winter][:christmas] << supply | |
# holiday_hash[:winter][:new_years] << supply | |
# { | |
# :christmas => ["Lights", "Wreath"], | |
# :new_years => ["Party Hats"] | |
# } | |
holiday_hash[:winter].each_pair do |holiday, supplies| | |
supplies << supply | |
end | |
end | |
def add_supply_to_memorial_day(holiday_hash, supply) | |
# again, holiday_hash is the same as the ones above | |
# add the second argument to the memorial day array | |
holiday_hash[:spring][:memorial_day] << supply | |
end | |
def add_new_holiday_with_supplies(holiday_hash, season, holiday_name, supply_array) | |
# code here | |
# season => :winter, holiday_name => :christmas, supply_array | |
holiday_hash[season][holiday_name] = supply_array | |
# remember to return the updated hash | |
holiday_hash | |
end | |
def all_winter_holiday_supplies(holiday_hash) | |
# return an array of all of the supplies that are used in the winter season | |
container = [] | |
holiday_hash[:winter].each_pair do |holiday, supplies| | |
container = container + supplies | |
end | |
container | |
end | |
def all_supplies_in_holidays(holiday_hash) | |
# iterate through holiday_hash and print items such that your readout resembles: | |
# Winter: | |
# Christmas: Lights, Wreath | |
# New Years: Party Hats | |
# Summer: | |
# Fourth Of July: Fireworks, BBQ | |
# etc. | |
holiday_hash.each_pair do |season, holidays| | |
puts "#{season.to_s.capitalize}:" | |
holidays.each_pair do |holiday, supplies| | |
new_holiday = holiday.to_s.gsub('_',' ').split.collect {|word| word.capitalize}.join(" ") | |
puts " #{new_holiday}: #{supplies.join(", ")}" | |
end | |
end | |
end | |
def all_holidays_with_bbq(holiday_hash) | |
# return an array of holiday names (as symbols) where supply lists | |
# include the string "BBQ" | |
container = [] | |
holiday_hash.each_pair do |season, holidays| | |
holidays.each_pair do |holiday, supplies| | |
container << holiday if supplies.include?("BBQ") | |
end | |
end | |
container | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment