Created
January 9, 2016 04:20
-
-
Save todlazarov/65fdf8a6cbbe06f5a91d 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
# Given the munsters hash below | |
munsters = { | |
"Herman" => { "age" => 32, "gender" => "male" }, | |
"Lily" => { "age" => 30, "gender" => "female" }, | |
"Grandpa" => { "age" => 402, "gender" => "male" }, | |
"Eddie" => { "age" => 10, "gender" => "male" }, | |
"Marilyn" => { "age" => 23, "gender" => "female"} | |
} | |
# Modify the hash such that each member of the Munster family has an additional "age_group" key that has one of three values describing the age group the family member is in (kid, adult, or senior). Your solution should produce the hash below | |
# { "Herman" => { "age" => 32, "gender" => "male", "age_group" => "adult" }, | |
# "Lily" => {"age" => 30, "gender" => "female", "age_group" => "adult" }, | |
# "Grandpa" => { "age" => 402, "gender" => "male", "age_group" => "senior" }, | |
# "Eddie" => { "age" => 10, "gender" => "male", "age_group" => "kid" }, | |
# "Marilyn" => { "age" => 23, "gender" => "female", "age_group" => "adult" } } | |
# Note: a kid is in the age range 0 - 17, an adult is in the range 18 - 64 and a senior is aged 65+. | |
# hint: try using a case statement along with Ruby Range objects in your solution | |
puts munsters["Herman"]["age"] | |
munsters.each do |each| | |
puts [each]["age"] | |
case [each]["age"] | |
when 0..17 | |
puts "kid" | |
when 18..64 | |
puts "adult" | |
when 65..1000 | |
puts "senior" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment