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
33 changes: 33 additions & 0 deletions board-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}