Created
October 1, 2013 14:07
-
-
Save samueldowens/6778993 to your computer and use it in GitHub Desktop.
holiday supplier questions
This file contains 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
1. holiday_supplies[:summer][:forth_of_july][1] | |
2. holiday_supplies[:winter][:christmas] << "Tree" | |
3. holiday_supplies[:spring][:memorial_day] << "Charcoal" | |
4. holiday_supplies[:summer].merge!(:august_second => ["cake", "booze"]) | |
5. | |
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] | |
}, | |
:spring => { | |
:memorial_day => ["BBQ"] | |
} | |
} | |
def collect_wint_supplies(hash) | |
supplies = [] | |
hash[:winter].each_value do |value| | |
supplies += value.map { |newval| newval } | |
end | |
supplies | |
end | |
6. | |
def list_supplies(hash) | |
hash.each do |key, value| | |
puts "#{key.to_s.capitalize}: " | |
value.each do |key, value| | |
value.map! { |value| value.capitalize } | |
puts " #{key.to_s.capitalize}: #{value.join(" and ")}" | |
end | |
end | |
end | |
7. | |
def holidays_with_bbqs(hash) | |
output = [] | |
hash.each_value do |holiday| | |
holiday.each_value do |supplies| | |
if supplies == "bbq" | |
output << holiday | |
end | |
end | |
end | |
output | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment