Skip to content

Instantly share code, notes, and snippets.

@chhhris
Created June 11, 2013 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chhhris/5754576 to your computer and use it in GitHub Desktop.
Save chhhris/5754576 to your computer and use it in GitHub Desktop.
$basketball_game =
{
:team_1 =>
{
:team_name => "Knicks",
:colors => ["blue", "orange"],
:player_1 =>
{
:name => "Patrick Ewing",
:jersey => 33,
:shoe => 18,
:stats =>
{
:points => 35,
:rebounds => 15,
:assists => 8,
:steals => 1,
:blocks => 3,
:dunks => 2
},
},
:player_2 =>
{
:name => "John Starks",
:jersey => 3,
:shoe => 14,
:stats =>
{
:points => 17,
:rebounds => 4,
:assists => 4,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_3 =>
{
:name => "Charles Oakley",
:jersey => 34,
:shoe => 18,
:stats =>
{
:points => 13,
:rebounds => 11,
:assists => 3,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_4 =>
{
:name => "Derek Harper",
:jersey => 1,
:shoe => 13,
:stats =>
{
:points => 7,
:rebounds => 4,
:assists => 8,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_5 =>
{
:name => "Anthony Mason",
:jersey => 8,
:shoe => 17,
:stats =>
{
:points => 9,
:rebounds => 4,
:assists => 7,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
},
:team_2 =>
{
:team_name => "Bulls",
:colors => ["red","black"],
:player_6 =>
{
:name => "Michael Jordan",
:number => 23,
:shoe_size => 16,
:stats =>
{
:points => 43,
:rebounds => 4,
:assists => 4,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_7 =>
{
:name => "Scottie Pippen",
:jersey => 31,
:shoe => 16,
:stats =>
{
:points => 23,
:rebounds => 4,
:assists => 5,
:steals => 2,
:blocks => 1,
:dunks => 1
},
},
:player_8 =>
{
:name => "Steve Kerr",
:jersey => 2,
:shoe => 13,
:stats =>
{
:points => 7,
:rebounds => 1,
:assists => 2,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_9 =>
{
:name => "Horace Grant",
:jersey => 35,
:shoe => 16,
:stats =>
{
:points => 3,
:rebounds => 14,
:assists => 4,
:steals => 1,
:blocks => 1,
:dunks => 1
},
},
:player_10 =>
{
:name => "Luc Longley",
:jersey => 35,
:shoe => 19,
:stats =>
{
:points => 3,
:rebounds => 4,
:assists => 4,
:steals => 1,
:blocks => 1,
:dunks => 1
}
}
}
}
# basketball_results = Hash.new
# songs.each do |song|
# song_array = song.split("-")
# artist = song_array[0].strip
# album = song_array[1].strip
# track = song_array[2].strip
# organized_library[artist.to_sym] ||={}
# organized_library[artist.to_sym][album.to_sym] ||={}
# organized_library[artist.to_sym][album.to_sym] << track
# Using the power of Ruby, and the Hashes you created above, answer the following questions:
# Return the number of points scored for any player.
puts "#{$basketball_game[:team_1][:player_1][:stats][:points]}"
# Return the shoe size for any player.
puts "#{$basketball_game[:team_2][:player_9][:shoe]}"
# Return both colors for any team.
puts "#{$basketball_game[:team_1][:colors]}"
# Return both teams names.
puts "#{$basketball_game[:team_1][:team_name]} + #{$basketball_game[:team_2][:team_name]}"
# Return all the player numbers for a team.
for number in (1..5)
puts "#{$basketball_game[:team_1]["player_#{number}".to_sym][:jersey]}"
end
# Return all the stats for a player.
puts "#{$basketball_game[:team_1][:player_1][:stats]}"
# Return the rebounds for the player with the largest shoe size.
puts "Out of my league"
# Bonus Questions:
# Define methods to return the answer to the following questions:
# Which player has the most points?
# Which team has the most points?
# Which player has the longest name?
# Super Bonus:
# Write a method that returns true if the player with the longest name had the most steals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment