Skip to content

Commit

Permalink
Lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
Cool-Katt committed Apr 9, 2024
1 parent 3c65df2 commit 67aa16e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions exercises/practice/state-of-tic-tac-toe/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const gamestate = (board) => {
let gridSize = board.length;
let numberOfX = board.join('').match(/X/g)?.length ?? 0
let numberOfO = board.join('').match(/O/g)?.length ?? 0
let numberOfX = board.join('').match(/X/g)?.length ?? 0;
let numberOfO = board.join('').match(/O/g)?.length ?? 0;
let scorringArray = Array(gridSize * 2 + 2).fill(null);
let boardAsNumbers = board
.map((row) =>
Expand All @@ -17,23 +17,25 @@ export const gamestate = (board) => {
let [row, col] = [Math.floor(index / gridSize), index % gridSize];
scorringArray[row] += Number(element);
scorringArray[gridSize + col] += Number(element);
(row === col) && (scorringArray[2 * gridSize] += Number(element));
(gridSize - 1 - col === row) && (scorringArray[2 * gridSize + 1] += Number(element));
row === col && (scorringArray[2 * gridSize] += Number(element));
gridSize - 1 - col === row &&
(scorringArray[2 * gridSize + 1] += Number(element));
});

switch (true) {
case numberOfX - numberOfO > 1:
throw new Error('Wrong turn order: X went twice')
throw new Error('Wrong turn order: X went twice');
case numberOfX - numberOfO < 0:
throw new Error('Wrong turn order: O started')
throw new Error('Wrong turn order: O started');
case scorringArray.includes(gridSize) && scorringArray.includes(-gridSize):
throw new Error('Impossible board: game should have ended after the game was won')
throw new Error(
'Impossible board: game should have ended after the game was won',
);
case scorringArray.includes(gridSize) || scorringArray.includes(-gridSize):
return 'win'
case boardAsNumbers.includes('0'):
return 'ongoing'
return 'win';
case boardAsNumbers.includes('0'):
return 'ongoing';
default:
return 'draw'
return 'draw';
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('Invalid boards', () => {
const expected = new Error(
'Impossible board: game should have ended after the game was won',
);
const actual = () => gamestate(board);
const actual = () => gamestate(board);
expect(actual).toThrow(expected);
});
});

0 comments on commit 67aa16e

Please sign in to comment.