Skip to content

Commit 6fccdab

Browse files
authored
Use TS optional chaining (#11)
1 parent c16f2af commit 6fccdab

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.vscode

src/load-game.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import gameSettings from "../settings/game.json";
22
import { Board, checkTile, isOutOfBounds, Turtle } from "./board";
33
import { Tile } from "./navigation";
44

5-
const parseTile = (tile: Tile) => Boolean(tile && tile.x >= 0 && tile.y >= 0);
5+
const parseTile = (tile: Tile) => Boolean(tile?.x >= 0 && tile?.y >= 0);
66

77
const getBoard = ({
88
xLength,
@@ -15,8 +15,7 @@ const getBoard = ({
1515
xLength > 0 &&
1616
yLength > 0 &&
1717
parseTile(exit) &&
18-
mines &&
19-
mines.length &&
18+
mines?.length &&
2019
mines.every(parseTile)
2120
)
2221
) {

src/load-moves.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import movesSettings from "../settings/moves.json";
22
import { Action } from "./board";
33

44
const isValid = (sequence: Action[]) =>
5-
Boolean(
6-
sequence && sequence.length && sequence.every(a => a === "m" || a === "r")
7-
);
5+
Boolean(sequence?.length && sequence.every(a => a === "m" || a === "r"));
86

97
export const loadMoves = () => {
108
if (!movesSettings) {

0 commit comments

Comments
 (0)