diff --git a/Project-11-Tic-Tac-Toe/package-lock.json b/Project-11-Tic-Tac-Toe/package-lock.json
index 858209f..917dcda 100644
--- a/Project-11-Tic-Tac-Toe/package-lock.json
+++ b/Project-11-Tic-Tac-Toe/package-lock.json
@@ -8,6 +8,7 @@
"name": "react-essentials-deep-dive-adv",
"version": "0.0.0",
"dependencies": {
+ "i": "^0.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
@@ -2226,6 +2227,14 @@
"node": ">= 0.4"
}
},
+ "node_modules/i": {
+ "version": "0.3.7",
+ "resolved": "https://registry.npmjs.org/i/-/i-0.3.7.tgz",
+ "integrity": "sha512-FYz4wlXgkQwIPqhzC5TdNMLSE5+GS1IIDJZY/1ZiEPCT2S3COUVZeT5OW4BmW4r5LHLQuOosSwsvnroG9GR59Q==",
+ "engines": {
+ "node": ">=0.4"
+ }
+ },
"node_modules/ignore": {
"version": "5.2.4",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
diff --git a/Project-11-Tic-Tac-Toe/package.json b/Project-11-Tic-Tac-Toe/package.json
index bf4de9a..aaa5514 100644
--- a/Project-11-Tic-Tac-Toe/package.json
+++ b/Project-11-Tic-Tac-Toe/package.json
@@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
+ "i": "^0.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/Project-11-Tic-Tac-Toe/src/App.jsx b/Project-11-Tic-Tac-Toe/src/App.jsx
index 310e8e6..854e272 100644
--- a/Project-11-Tic-Tac-Toe/src/App.jsx
+++ b/Project-11-Tic-Tac-Toe/src/App.jsx
@@ -42,6 +42,7 @@ function deriveGameBoard(gameTurns) {
function deriveWinner(gameBoard, players) {
let winner;
+ let winningCombination = null; // Added this line
for (const combination of WINNING_COMBINATIONS) {
const firstSquareSymbol = gameBoard[combination[0].row][combination[0].col];
const secondSquareSymbol =
@@ -54,10 +55,12 @@ function deriveWinner(gameBoard, players) {
firstSquareSymbol === thirdSquareSymbol
) {
winner = players[firstSquareSymbol];
+ winningCombination = combination; // Added this line
+ break;
}
}
- return winner;
+ return { winner, winningCombination }; // Changed this line to return both winner and winningCombination
}
function App() {
@@ -66,7 +69,7 @@ function App() {
const activePlayer = deriveActivePlayer(gameTurns);
const gameBoard = deriveGameBoard(gameTurns);
- const winner = deriveWinner(gameBoard, players);
+ const { winner, winningCombination } = deriveWinner(gameBoard, players); // Changed this line
const hasDraw = gameTurns.length === 9 && !winner;
const handleSelectSquare = (rowIndex, colIndex) => {
@@ -118,7 +121,11 @@ function App() {
{(winner || hasDraw) && (