Last active
December 21, 2015 21:39
-
-
Save dmehrotra/6370154 to your computer and use it in GitHub Desktop.
alpha 3
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 | |
def start(teams) | |
teams=[] | |
2.times do | |
teams << enter_info | |
p '-------team 2-------' | |
end | |
identify_winner(teams) | |
end | |
def identify_winner(teams) | |
if no_dups?(teams) | |
higher_score(teams) | |
puts "#{teams.find{|team| team['team_score'] == higher_score(teams)}['team_name']} is the winner" | |
puts "play again? " | |
input = gets.chomp | |
if input == 'y' | |
start(teams) | |
else | |
puts 'thanks' | |
end | |
else | |
puts 'duplicate names, try again' | |
end | |
end | |
start(teams) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment