I'm having trouble finding the largest value associated with a shoe size key in a hash. Here is what I have so far
def biggest_shoe
max_size = nil
game_hash.each do |location, team_data|
team_data[:players].each do |player, stats|
size = stats[:shoe]
if max_size < size
max_size = size
#binding.pry
end
end
end
end
I was able to successfully grab the individual value of a shoe throughout iteration with stats[:shoe] but from there I haven't figured a way to pull the largest size from the hash its iterating.
The hash:
def game_hash
{
home: {
:team_name => "Brooklyn Nets",
:colors => ["Black", "White"],
:players => {
"Alan Anderson" => {
:number => 0,
:shoe => 16,
:points => 22,
:rebounds => 12,
:assists => 12,
:steals => 3,
:blocks => 1,
:slam_dunks => 1
},
"Reggie Evans" => {
:number => 30,
:shoe => 14,
:points => 12,
:rebounds => 12,
:assists => 12,
:steals => 12,
:blocks => 12,
:slam_dunks => 7
},
"Brook Lopez" => {
:number => 11,
:shoe => 17,
:points => 17,
:rebounds => 19,
:assists => 10,
:steals => 3,
:blocks => 1,
:slam_dunks => 15
},
"Mason Plumlee" => {
:number => 1,
:shoe => 19,
:points => 26,
:rebounds => 12,
:assists => 6,
:steals => 3,
:blocks => 8,
:slam_dunks => 5
},
"Jason Terry" => {
:number => 31,
:shoe => 15,
:points => 19,
:rebounds => 2,
:assists => 2,
:steals => 4,
:blocks => 11,
:slam_dunks => 1
}
}
},
away: {
:team_name => "Charlotte Hornets",
:colors => ["Turquoise", "Purple"],
:players => {
"Jeff Adrien" => {
:number => 4,
:shoe => 18,
:points => 10,
:rebounds => 1,
:assists => 1,
:steals => 2,
:blocks => 7,
:slam_dunks => 2,
},
"Bismak Biyombo" => {
:number => 0,
:shoe => 16,
:points => 12,
:rebounds => 4,
:assists => 7,
:steals => 7,
:blocks => 15,
:slam_dunks => 10
},
"DeSagna Diop" => {
:number => 2,
:shoe => 14,
:points => 24,
:rebounds => 12,
:assists => 12,
:steals => 4,
:blocks => 5,
:slam_dunks => 5
},
"Ben Gordon" => {
:number => 8,
:shoe => 15,
:points => 33,
:rebounds => 3,
:assists => 2,
:steals => 1,
:blocks => 1,
:slam_dunks => 0
},
"Brendan Haywood" => {
:number => 33,
:shoe => 15,
:points => 6,
:rebounds => 12,
:assists => 12,
:steals => 22,
:blocks => 5,
:slam_dunks => 12
}
}
}
}
end
game_hashcannot be a hash as it is local to the methodbiggest_shoe. Do you meangame_hashto be a method (despite its name)? If it is to be a hash it needs to be passed to the method as an argument.