Created
August 28, 2013 19:13
-
-
Save dmehrotra/6370015 to your computer and use it in GitHub Desktop.
alpha
This file contains hidden or 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
teams =[] | |
def no_dups?(teams) | |
names=[] | |
teams.each do |team| | |
if names.include?(team['team_name']) | |
return false | |
else | |
names << team['team_name'] | |
end | |
end | |
end | |
def higher_score(teams) | |
highest = 0; | |
teams.each do |team| | |
if team['team_score'].to_i > highest | |
highest = team['team_score'].to_i | |
end | |
end | |
return highest | |
end | |
def enter_info | |
team={} | |
puts "what was this team's name?" | |
team_name = gets.chomp | |
puts "what was this team's score? " | |
team_score = gets.chomp.to_i | |
team['team_name'] = team_name | |
team['team_score'] = team_score | |
return team | |
end | |
2.times { teams << enter_info } | |
if no_dups?(teams) | |
higher_score(teams) | |
puts "#{teams.find{|team| team['team_score'] == higher_score(teams)}['team_name']} is the winner" | |
else | |
puts 'duplicate names, try again' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment