-
Notifications
You must be signed in to change notification settings - Fork 72
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
Paperr--AndreaPalacios #65
base: master
Are you sure you want to change the base?
Conversation
const updateSquares=(id)=>{ | ||
if (winner !== null) return; | ||
|
||
const newSquares = [...squares]; |
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.
This works, but if you were attempting to use it to build a copy of squares, it doesn't quite do that. Consider the following:
> const a = [[1,2,3],[4,5,6],[7,8,9]]
> console.log(a)
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
> const b = [...a]
> console.log(b)
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
> a[1][1] = "r"
'r'
> console.log(b)
[ [ 1, 2, 3 ], [ 4, 'r', 6 ], [ 7, 8, 9 ] ]
> a == b
false
> a[1] == b[1]
true
In the above example, arrays a & b are using the same inner arrays. This isn't a problem in this particular case, but I just wanted to point out that the [...array] operator is just creating a copy of the outer array, not of the inner arrays.
|
||
|
||
const updateStatus= () => { |
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.
Great helper function!
}; | ||
|
||
/*update turn is working*/ | ||
const updateTurn = ()=> { |
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.
👍
setSquares(generateSquares()); | ||
setPlayer(PLAYER_1); | ||
setStatus('Let\'s Play!'); | ||
setWinner(null); | ||
setTurnCount(0) |
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.
Great code re-use!
if (squares[0][i].value === squares[1][i].value && | ||
squares[1][i].value === squares[2][i].value && | ||
squares[0][i].value !== '') { | ||
return squares[0][i].value |
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.
This chunk of code is repeated for rows and diagonals, the only changes are which points are being checked. I recommend thinking about creating a helper function that does this comparison function to improve readability.
Great work on this project! Nice work with the reset and tie extensions. This project is green. |
No description provided.