Paperr--AndreaPalacios#65
Conversation
| const updateSquares=(id)=>{ | ||
| if (winner !== null) return; | ||
|
|
||
| const newSquares = [...squares]; |
There was a problem hiding this comment.
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= () => { |
| }; | ||
|
|
||
| /*update turn is working*/ | ||
| const updateTurn = ()=> { |
| setSquares(generateSquares()); | ||
| setPlayer(PLAYER_1); | ||
| setStatus('Let\'s Play!'); | ||
| setWinner(null); | ||
| setTurnCount(0) |
| 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.
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.