Last active
December 24, 2015 09:29
-
-
Save BandanaKM/6778066 to your computer and use it in GitHub Desktop.
Hashes: Holidays homework
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
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] | |
}, | |
:spring => { | |
:memorial_day => ["BBQ"] | |
} | |
} | |
# How would you access the second supply for the forth_of_july? ex: holiday_supplies[:spring][:memorial_day][0] | |
1. | |
holiday_supplies[:summer][:forth_of_july][1] | |
# Add a supply to a Winter holiday. | |
2. holiday_supplies[:winter][:new_year] << 'kazoos' | |
# Add a supply to memorial day. | |
3. holiday_supplies[:spring][:memorial_day] << 'ketchep' | |
# Add a new holiday to any season with supplies. | |
4. holiday_supplies[:spring][:harvest_festival] | |
# Write a method to collect all Winter supplies from all the winter holidays. ex: winter_suppliers(holiday_supplies) #=> ["Lights", "Wreath", etc] | |
5. | |
winter_supplies | |
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] | |
}, | |
:spring => { | |
:memorial_day => ["BBQ"] | |
} | |
} | |
def winter_supplies(supplies_hash) | |
winter_supplies = [] | |
supplies_hash.map do |season, holiday_hash| | |
if season == :winter | |
holiday_hash.map do |holiday, supplies_array| | |
supplies_array.map do |supplies_item| | |
winter_supplies << supplies_item | |
end | |
end | |
end | |
end | |
p winter_supplies | |
end | |
winter_supplies(holiday_supplies) | |
# Write a loop to list out all the supplies you have for each holiday and the season. | |
6. select_season_holidays | |
# Output: | |
# Winter: | |
# Christmas: Lights and Wreath | |
# New Years: Party Hats | |
# Write a method to collect all holidays with BBQ. | |
# holidays_with_bbqs(holiday_supplies) #=> [:fourth_of_july, :memorial_day] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment