-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panda Level #14
base: master
Are you sure you want to change the base?
Panda Level #14
Conversation
end | ||
|
||
private | ||
def build_turns | ||
13.times.map do | ||
Turn.new(@opponent_a.strike, @opponent_b.strike) | ||
@turns = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're looping over something to collect items into an array, I'd rather you use map.
@turns = 13.times.map do |x|
turn = Turn.new(@opponent_a.strike, @opponent_b.strike)
if @opponent_a.strike == turn.winner
@opponent_a
else
@opponent_b
end
end
@turns.each_with_index do |winner, i|
puts "#{winner.name} won round #{i+1}!"
end
I also separated the running of the turns with the reporting of the turns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. So in this case I'm interested in getting an array of winners for a given round. map
returns an array so it more directly conveys what I intend to receive. Whereas in my implementation, I went in a round about way to get there by separately instantiating an array then using an iterator to populate that array. Is this a good way to look at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep exactly. 😃
Nice submission -- let me know if you have any questions. |
This was a little tougher than I was anticipating. Having a better understanding of the current implementation definitely helps.