Last active
August 29, 2015 14:01
-
-
Save hchood/e49098b075a707346f79 to your computer and use it in GitHub Desktop.
array and hash drills
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
############################ | |
# Array & hash drills | |
############################ | |
first_names = ["Richard", "Adam", "Sam", "Helen", "Eric"] | |
# Print each name in the array | |
# Downcase each name in the array | |
# Print the third name in the array | |
full_names = [ | |
{ first_name: "Richard", last_name: "Davis" }, | |
{ first_name: "Adam", last_name: "Sheehan" }, | |
{ first_name: "Sam", last_name: "McTaggart" }, | |
{ first_name: "Helen", last_name: "Hood" }, | |
{ first_name: "Eric", last_name: "Kelly" } | |
] | |
# Print the 4th person's full name | |
# Print each person's full name | |
# Greet each person by their full name like so: "Hi, Helen Hood!" | |
# Greet each person by their first name & last initial like so: "Hi, Helen H.!" | |
richard_hash = { | |
first_name: "Richard", | |
last_name: "Davis", | |
favorite_foods: ["dumplings", "sushi", "pizza"] | |
} | |
adam_hash = { | |
first_name: "Adam", | |
last_name: "Sheehan", | |
favorite_foods: ["pad thai", "beer"] | |
} | |
sam_hash = { | |
first_name: "Sam", | |
last_name: "McTaggart", | |
favorite_foods: [""] | |
} | |
helen_hash = { | |
first_name: "Helen", | |
last_name: "Hood", | |
} | |
eric_hash = { | |
first_name: "Eric", | |
last_name: "Kelly", | |
favorite_foods: ["lasagna", "hamburgers"] | |
} | |
# Print Sam's full name | |
# Print Richard's first favorite food | |
# Print Adam's second favorite food | |
# Print Helen's third favorite food | |
# Create an array called people that contains all of the hashes above | |
# Using that hash, repeat the following: | |
# => Print Richard's first favorite food | |
# => Print Adam's second favorite food | |
# => Print Helen's third favorite food | |
# Add Faizaan to our people array: | |
# => first name: Faizaan | |
# => last name: Shamsi | |
# => favorite foods: mango chutney, bad chinese food, Soylent | |
# Print each person's name and how many favorite foods they have, like so: | |
# "Adam Sheehan has 2 favorite foods." | |
# Add people's ages to their hash: | |
# => Adam is 28 | |
# => Sam, Faizaan, and Eric are 24 | |
# => Helen is 27 | |
# Say it's a year later -- increment everyone's age by 1 | |
# For each person, print the following: | |
# => If they are under 25: "Sam is a spring chicken!" | |
# => If they are over 25: "Helen is over the hill!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment