tags | languages | resources |
---|---|---|
hashes, iteration |
ruby |
1 |
Great news! You're going to an NBA game! The only catch is that you've been volunteered to keep stats at the game.
Using Nested Hashes, define a game, with two teams, their players, and the players stats:
- The game has two teams
- A team has:
- name
- colors (x2)
- Each player should have a:
- name
- jersey_number
- shoe_size
- Each player should have the following stats:
- points
- rebounds
- assists
- steals
- blocks
- slam_dunks
Use the following seed data to structure your game hash as suggested above. When designing your nested hash structure think about how one might want to access the data.
Remember to run learn
to see what the tests expect.
- Home Team = Brooklyn Nets, Colors = Black, White
- Away Team = Charlotte Hornets, Colors = Turquoise, Purple
Jeff Adrien | Bismak Biyombo | DeSagna Diop | Ben Gordon | Brendan Haywood | |
---|---|---|---|---|---|
Team | Charlotte Hornets | Charlotte Hornets | Charlotte Hornets | Charlet Hornets | Charlotte Hornets |
Number | 4 | 0 | 2 | 8 | 33 |
Shoe | 18 | 16 | 14 | 15 | 15 |
Points | 10 | 12 | 24 | 33 | 6 |
Rebounds | 1 | 4 | 12 | 3 | 12 |
Assists | 1 | 7 | 12 | 2 | 12 |
Steals | 2 | 7 | 4 | 1 | 22 |
Blocks | 7 | 15 | 5 | 1 | 5 |
Slam Dunks | 2 | 10 | 5 | 0 | 12 |
Alan Anderson | Reggie Evans | Brook Lopez | Mason Plumlee | Jason Terry | |
---|---|---|---|---|---|
Team | Brooklyn Nets | Brooklyn Nets | Brooklyn Nets | Brooklyn Nets | Brooklyn Nets |
Number | 0 | 30 | 11 | 1 | 31 |
Shoe | 16 | 14 | 17 | 19 | 15 |
Points | 22 | 12 | 17 | 26 | 19 |
Rebounds | 12 | 12 | 19 | 12 | 2 |
Assists | 12 | 12 | 10 | 6 | 2 |
Steals | 3 | 12 | 3 | 3 | 4 |
Blocks | 1 | 12 | 1 | 8 | 11 |
Slam Dunks | 1 | 7 | 15 | 5 | 1 |
Using the power of Ruby, and the hashes you created, write methods to complete the following:
-
Returns your game hash. Call the method
game_hash
. -
Return the number of points scored for any player, given that player's name as a string. Call the method
num_points_scored
. -
Return the shoe size for any player, given that player's name. Call the method
shoe_size
. -
Return both colors for any team, given the team name. Call the method
team_colors
. -
Return both teams names, given the game_hash. Call the method
team_names
. Note: Since you have a methodgame_hash
that returns your hash, there is no need to pass it in as an argument! You can just call it from within yourteam_names
method. -
Return all the player numbers for a team, given a team name. Call the method
player_numbers
. -
Return all the stats for a player, given a player's name. The stats should be returned as a hash, which each stat name as a key and the corresponding stat as a value. Call the method
player_stats
. eg:player_stats("Alan Anderson") => { :number => 0, :shoe => 16, :points => 22, :rebounds => 12, :assists => 12, :steals => 3, :blocks => 1, :slam_dunks => 1 }
-
Return the number of rebounds for the player with the largest shoe size. Call the method
big_shoe_rebounds
.
Bonus Questions:
Define methods to return the answer to the following questions:
-
Which player has the most points? Call the method
most_points_scored
. -
Which team has the most points? Call the method
winning_team
. -
Which player has the longest name? Call the method
player_with_longest_name
.
Super Bonus:
- Write a method that returns true if the player with the longest name had the most steals. Call the method
long_name_steals_a_ton?
.