Created
September 30, 2013 23:00
-
-
Save manleyhimself/6771541 to your computer and use it in GitHub Desktop.
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"] | |
} | |
} | |
def winter_supplies(main_hash) | |
w_supplies = [] | |
main_hash.map do |season,holiday_hash| | |
if season == :winter | |
holiday_hash.map do |holidays, supplies_array| | |
supplies_array.map do |supplies| | |
w_supplies << supplies | |
end | |
end | |
end | |
end | |
w_supplies | |
end | |
def supply_loop(main_hash) | |
main_hash.map do |season,holiday_hash| | |
holiday_hash.map do |holidays, supplies_array| | |
puts "#{season}: #{holidays}: #{supplies_array.join(" , ")}" if supplies_array.length > 1 | |
supplies_array.map do |supplies| | |
puts "#{season}: #{holidays}: #{supplies}" if supplies_array.length <= 1 | |
end | |
end | |
end | |
end | |
# #1. How would you access the second supply for the forth_of_july? ex: holiday_supplies[:spring][:memorial_day][0] | |
# holiday_supplies[:summer][:forth_of_july][1] | |
# #2. Add a supply to a Winter holiday. | |
# holiday_supplies[:winter][:christmas][2] = "Mistletoe ; )" | |
# #3. Add a supply to memorial day. | |
# holiday_supplies[:spring][:memorial_day][1] = "Booze" | |
# #4. Add a new holiday to any season with supplies. | |
# holiday_supplies[:winter][:hannukah] = [] | |
# holiday_supplies[:winter][:hannukah][0..2] = "candles","dradels","presents" | |
# #5. Write a method to collect all Winter supplies from all the winter holidays. ex: winter_suppliers(holiday_supplies) #=> ["Lights", "Wreath", etc] | |
# see winter_supplies | |
# #6. Write a loop to list out all the supplies you have for each holiday and the season. | |
# see supply_loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment