From 1584ba30ea595acd74680f76644822f38bbbf07a Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Sat, 22 Nov 2025 12:30:40 +0000 Subject: [PATCH 1/6] Implement printBoard function to display tic-tac-toe board in the terminal --- board-printer.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/board-printer.js b/board-printer.js index e11a262..059b1e3 100644 --- a/board-printer.js +++ b/board-printer.js @@ -15,8 +15,22 @@ ================= Test your function by calling it with an example tic-tac-toe board. */ + +let board = [ + ['_', '_', '_'], + ['_', '_', '_'], + ['_', '_', '_'] +] + export function printBoard(board) { -} + for (const row of board) { // loop array of 3 arrays + const rowString = row.map(cell => ` ${cell} `).join('|'); // map each cell to a string with spaces and join with '|' + console.log(rowString); // print the row string + console.log('-----------'); // print separator after each row + } + board.pop(); // remove the last separator to avoid extra line +}; +console.log(printBoard(board)); /* Given a tic-tac-toe board (an array of arrays), @@ -24,4 +38,5 @@ export function printBoard(board) { - return false if there are still moves that can be made */ export function checkIfNoMovesLeft(board) { + } From 55f26781c111099094a6e72641768441dea0fc0e Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Sat, 22 Nov 2025 13:02:33 +0000 Subject: [PATCH 2/6] Refactor printBoard function to improve output formatting and clarity --- board-printer.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/board-printer.js b/board-printer.js index 059b1e3..00a678c 100644 --- a/board-printer.js +++ b/board-printer.js @@ -17,18 +17,20 @@ */ let board = [ - ['_', '_', '_'], - ['_', '_', '_'], - ['_', '_', '_'] + [' ', ' ', ' '], + [' ', ' ', ' '], + [' ', ' ', ' '] ] export function printBoard(board) { for (const row of board) { // loop array of 3 arrays const rowString = row.map(cell => ` ${cell} `).join('|'); // map each cell to a string with spaces and join with '|' console.log(rowString); // print the row string - console.log('-----------'); // print separator after each row + if (row !== board[board.length - 1]) { + console.log('-----------'); // print separator after each row + } } - board.pop(); // remove the last separator to avoid extra line + // remove the last separator to avoid extra line }; console.log(printBoard(board)); @@ -38,5 +40,12 @@ console.log(printBoard(board)); - return false if there are still moves that can be made */ export function checkIfNoMovesLeft(board) { - + for (let row of board) { + for (let cell of row) { + if (cell === '_') { + return false; + } + } + } + return true; } From c7564b97cc959298195b47d14d67eabebc7c4285 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Sun, 23 Nov 2025 12:26:23 +0000 Subject: [PATCH 3/6] Refactor printBoard function to use index-based iteration and improve separator logic --- board-printer.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/board-printer.js b/board-printer.js index 00a678c..f5d32a3 100644 --- a/board-printer.js +++ b/board-printer.js @@ -23,16 +23,15 @@ let board = [ ] export function printBoard(board) { - for (const row of board) { // loop array of 3 arrays - const rowString = row.map(cell => ` ${cell} `).join('|'); // map each cell to a string with spaces and join with '|' + for (let i = 0; i < board.length; i++) { // loop array of 3 arrays + const rowString = board[i].map(cell => ` ${cell} `).join('|'); // map each cell to a string with spaces and join with '|' console.log(rowString); // print the row string - if (row !== board[board.length - 1]) { - console.log('-----------'); // print separator after each row + if (i < board.length - 1) { + console.log('-----------'); // print separator after each row except the last } } - // remove the last separator to avoid extra line }; -console.log(printBoard(board)); +printBoard(board); /* Given a tic-tac-toe board (an array of arrays), From f6eac8df360980e61ff92cc0ba92853203d0c0a7 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 4 Dec 2025 12:16:45 +0000 Subject: [PATCH 4/6] final --- board-printer.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/board-printer.js b/board-printer.js index f5d32a3..098d908 100644 --- a/board-printer.js +++ b/board-printer.js @@ -17,20 +17,22 @@ */ let board = [ - [' ', ' ', ' '], - [' ', ' ', ' '], - [' ', ' ', ' '] -] + [" ", " ", " "], + [" ", " ", " "], + [" ", " ", " "], +]; -export function printBoard(board) { - for (let i = 0; i < board.length; i++) { // loop array of 3 arrays - const rowString = board[i].map(cell => ` ${cell} `).join('|'); // map each cell to a string with spaces and join with '|' - console.log(rowString); // print the row string - if (i < board.length - 1) { - console.log('-----------'); // print separator after each row except the last - } +function printBoard(board) { + // Setting parameter board within the function printBoard + for (let i = 0; i < board.length; i++) { + // loop array of 3 arrays, adds count of one to index + const rowString = board[i].map((cell) => ` ${cell} `).join("|"); // map each cell to a string with spaces and join with '|' + console.log(rowString); // print the row string + if (i < board.length - 1) { + console.log("-----------"); // print separator after each row except the last } -}; + } +} printBoard(board); /* @@ -38,13 +40,13 @@ printBoard(board); - return true if there are no moves left to make (there are no more '_' values) - return false if there are still moves that can be made */ -export function checkIfNoMovesLeft(board) { - for (let row of board) { - for (let cell of row) { - if (cell === '_') { - return false; - } - } +function checkIfNoMovesLeft(board) { + for (let row of board) { + for (let cell of row) { + if (cell === " ") { + return false; + } } - return true; + } + return true; } From 822cb1d8eb9dc34c3b74927664123c1bbd4b389b Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 4 Dec 2025 12:49:14 +0000 Subject: [PATCH 5/6] exported function --- board-printer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board-printer.js b/board-printer.js index 098d908..37344d6 100644 --- a/board-printer.js +++ b/board-printer.js @@ -40,7 +40,7 @@ printBoard(board); - return true if there are no moves left to make (there are no more '_' values) - return false if there are still moves that can be made */ -function checkIfNoMovesLeft(board) { + export function checkIfNoMovesLeft(board) { for (let row of board) { for (let cell of row) { if (cell === " ") { From 37a6e2295939c714bd74ebd5f83d6da4b227525e Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Sat, 6 Dec 2025 13:19:27 +0000 Subject: [PATCH 6/6] "_" --- board-printer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/board-printer.js b/board-printer.js index 37344d6..c445868 100644 --- a/board-printer.js +++ b/board-printer.js @@ -17,12 +17,12 @@ */ let board = [ - [" ", " ", " "], - [" ", " ", " "], - [" ", " ", " "], + ["_", "_", "_"], + ["_", "_", "_"], + ["_", "_", "_"], ]; -function printBoard(board) { + export function printBoard(board) { // Setting parameter board within the function printBoard for (let i = 0; i < board.length; i++) { // loop array of 3 arrays, adds count of one to index @@ -43,7 +43,7 @@ printBoard(board); export function checkIfNoMovesLeft(board) { for (let row of board) { for (let cell of row) { - if (cell === " ") { + if (cell === "_") { return false; } }