From 2edeb893a4a1bdab36a5e8a5a7c685e8ea87cdf7 Mon Sep 17 00:00:00 2001 From: Benjamin Claassen Date: Fri, 17 Jan 2025 00:50:36 +0100 Subject: [PATCH] Added typedef for SudokuStates Removed unnecessary parameter --- reviews/BordedDev/sudoku.rewrite.js | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/reviews/BordedDev/sudoku.rewrite.js b/reviews/BordedDev/sudoku.rewrite.js index 7f0842d..42d7db5 100644 --- a/reviews/BordedDev/sudoku.rewrite.js +++ b/reviews/BordedDev/sudoku.rewrite.js @@ -21,20 +21,24 @@ function randInt(min, max) { } class SudokuPuzzle extends EventTarget { + /** + * @typedef {(number|null|undefined)[]} SudokuState + */ + /** * - * @type {(number|null)[][]} + * @type {SudokuState[]} */ #state = [] /** * - * @type {(number|null|undefined)[]} + * @type {SudokuState} */ #activeState = new Array(SUDOKU_GRID_SIZE) /** * - * @returns {(number|null|undefined)[]} + * @returns {SudokuState} */ get grid() { const gridValue = [...this.#activeState] @@ -61,7 +65,7 @@ class SudokuPuzzle extends EventTarget { /** * * @param serializedState {string} - * @returns {((number|null|undefined))[]} + * @returns {SudokuState} */ static #stateFromString(serializedState) { let cellIndex = 0 @@ -86,7 +90,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @param stateToSample {(number|null|undefined)[]} + * @param stateToSample {SudokuState} * @returns {undefined|number} */ #sampleRandomEmptyField(stateToSample = this.#activeState) { @@ -98,7 +102,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @param states {...(number|null|undefined)[][]} + * @param states {...SudokuState[]} */ static collapseStates(...states) { return Array.from({ length: SUDOKU_GRID_SIZE }, (_, i) => { @@ -113,7 +117,7 @@ class SudokuPuzzle extends EventTarget { /** * * @param slot {number} - * @param state {(number|null|undefined)[]} + * @param state {SudokuState} * @return {Set} */ #boxGetValues(slot, state = this.#activeState) { @@ -137,7 +141,7 @@ class SudokuPuzzle extends EventTarget { /** * * @param slot {number} - * @param state {(number|null|undefined)[]} + * @param state {SudokuState} * @return {Set} */ #crossGetValues(slot, state = this.#activeState) { @@ -176,7 +180,7 @@ class SudokuPuzzle extends EventTarget { /** * * @param slot {number} - * @param state {(number|null|undefined)[]} + * @param state {SudokuState} * @return {Set} */ getValues(slot, state = this.#activeState) { @@ -189,7 +193,7 @@ class SudokuPuzzle extends EventTarget { * * @param value {number} * @param slot {number} - * @param state {(number|null|undefined)[]} + * @param state {SudokuState} * @return boolean */ isValueValidForSlot(value, slot, state = this.#activeState) { @@ -200,7 +204,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @param newState {(number|null|undefined)[]} + * @param newState {SudokuState} */ fillRandomFieldInState(newState = Array.from({ length: SUDOKU_GRID_SIZE })) { const inProgressState = SudokuPuzzle.collapseStates( @@ -222,7 +226,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @returns {(number|null|undefined)[]} + * @returns {SudokuState} */ #generateRandomState() { const newState = Array.from({ length: SUDOKU_GRID_SIZE }) @@ -235,7 +239,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @returns {(number|null|undefined)[]} + * @returns {SudokuState} */ get baseState() { return this.#state[0] @@ -253,7 +257,7 @@ class SudokuPuzzle extends EventTarget { /** * - * @param newState {(number|null|undefined)[]} + * @param newState {SudokuState} */ applyState(newState) { this.#state.push(newState) @@ -367,7 +371,7 @@ class SudokuHost extends HTMLElement { }) this.#keyProcessors.set("m", () => { - for (const [_, cell] of this.#selectedCells) { + for (const [, cell] of this.#selectedCells) { cell.classList.toggle("marked") cell.classList.remove("selected") }