Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Panda Level #14

wants to merge 9 commits into from

Conversation

jperezish
Copy link

This was a little tougher than I was anticipating. Having a better understanding of the current implementation definitely helps.

end

private
def build_turns
13.times.map do
Turn.new(@opponent_a.strike, @opponent_b.strike)
@turns = []
Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly. 😃

@jwo
Copy link
Member

jwo commented Jan 8, 2014

Nice submission -- let me know if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants