Last active
August 29, 2015 14:07
-
-
Save danielbonnell/6769fb41e2f5f4603fd9 to your computer and use it in GitHub Desktop.
tic-tac-to challenge
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
def winner?(board) | |
@match = false | |
def check(type) | |
@match = true if type.uniq.length == 1 && !type.include?(" ") | |
end | |
board.each do |row| | |
check(row) | |
end | |
board.transpose.each do |col| | |
check(col) | |
end | |
diag1, diag2 = board.map.with_index { |row, i| [row[i], row[- i - 1]] }.transpose | |
check(diag1) | |
check(diag2) | |
@match | |
end |
I wasn't able to get your line 8 suggestion implemented. It just won't work no matter how I play with it in the editor. Thanks for the other tips though. I simplified the code just a bit more, although launchcop is still giving is 8/7 for complexity (down from 11/7).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 18:
is the same as
The result of that is already going to be true or false.
Which is also going to be returned implicitly since it's the last return value in the method Which means you don't have to explicitly write
return