From 3ad5f37b9b08dbca0a7e9b007700c07315fc211a Mon Sep 17 00:00:00 2001 From: Shayan Mahnam <95313895+Shayanma94@users.noreply.github.com> Date: Sun, 11 Dec 2022 23:11:18 +0000 Subject: [PATCH 1/2] board printer done --- board-printer.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/board-printer.js b/board-printer.js index e11a262..513d5ce 100644 --- a/board-printer.js +++ b/board-printer.js @@ -15,13 +15,46 @@ ================= Test your function by calling it with an example tic-tac-toe board. */ +// let board = [ +// ["X", "_", "_"], +// ["_", "X", "_"], +// ["O", "O", "X"], +// ]; + export function printBoard(board) { + board.forEach((row) => { + printRow(row); + console.log(`==========`) + }); +} + +function printRow(row) { + let newRow = row.map((el) => { + if (el === "_") { + return " " + } else { + return el + } + }); + + console.log(newRow.join(" | ")); } + +// printBoard(board); + /* Given a tic-tac-toe board (an array of arrays), - 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 i = 0; i < board.length; i++) { + for (let j = 0; j < board[i].length; j++) { + if (board[i][j] === "_") { + return false; + } + } + } + return true; } From 64bf6c8e094ec6f01253aaa9538fc91ca8ac5b3d Mon Sep 17 00:00:00 2001 From: Shayan Mahnam <95313895+Shayanma94@users.noreply.github.com> Date: Wed, 21 Dec 2022 13:01:57 +0000 Subject: [PATCH 2/2] bug fixed --- board-printer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board-printer.js b/board-printer.js index 513d5ce..ec62734 100644 --- a/board-printer.js +++ b/board-printer.js @@ -37,7 +37,7 @@ function printRow(row) { } }); - console.log(newRow.join(" | ")); + console.log(" " + newRow.join(" | ")); }