[basic] chessBoard author solution
This commit is contained in:
+18
-1
@@ -21,4 +21,21 @@ function chessBoard(size: number) {
|
|||||||
console.log(output)
|
console.log(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
chessBoard(8);
|
function chessBoardAthorSolution(size: number) {
|
||||||
|
let board = "";
|
||||||
|
|
||||||
|
for (let y = 0; y < size; y++) {
|
||||||
|
for (let x = 0; x < size; x++) {
|
||||||
|
if ((x + y) % 2 == 0)
|
||||||
|
board += " ";
|
||||||
|
else
|
||||||
|
board += "#";
|
||||||
|
}
|
||||||
|
board += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(board)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
chessBoardAthorSolution(10);
|
||||||
|
|||||||
Reference in New Issue
Block a user