Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions board-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,38 @@
=================
Test your function by calling it with an example tic-tac-toe board.
*/
export function printBoard(board) {

let 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
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);

/*
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) {
export function checkIfNoMovesLeft(board) {
for (let row of board) {
for (let cell of row) {
if (cell === "_") {
return false;
}
}
}
return true;
}