diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f5e091b..0e293408 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 'lts/*' + node-version: '>=22' cache: yarn - run: yarn install diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df77397..37d0c843 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Note: Many earlier versions are not specified, that's too much work. When a `@types` dependency updates, they almost always don't affect anything. +## v0.36.2 + +- (code) Use new Set methods, simplifies code. This shouldn't break support for old browsers. + ## v0.36.1 - (css) Fix explanation changing the size of Aside diff --git a/README.md b/README.md index 6d7c8421..e1ae51ef 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,6 @@ You can run `yarn install` and then `yarn npm audit` for the full report. ## Node version -This project does not seem to use node, but just in case, this uses `String.prototype.replaceAll`, so your node version must be `>=15.0.0`. +This project does not seem to use node, but just in case, this uses `Set.prototype.isSubsetOf`, so your node version must be `>=22.0.0`. Also, `@types/node` is usually on one of the latest versions, since github actions eventually deprecates old versions of node. If `@types/node` is incompatible with an earlier version of node, you can try downgrading the dependency, or post an issue if it doesn't work. Alternatively, if you're on gitpod run `nvm install 16` or higher. diff --git a/package.json b/package.json index bc3ca3d8..f71038ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solver", - "version": "0.36.1", + "version": "0.36.2", "private": true, "homepage": "https://icecream17.github.io/solver", "dependencies": { @@ -17,7 +17,7 @@ }, "devDependencies": { "@types/jest": "^27.0.2", - "@types/node": "^20.0.0", + "@types/node": "^22.0.0", "@types/react": "^17.0.34", "@types/react-dom": "^17.0.11", "eslint-plugin-jest-dom": "^4.0.0", @@ -39,10 +39,7 @@ }, "browserslist": { "production": [ - "supports prefers-color-scheme", - "not ios_saf < 14.5", - "not safari < 14.1", - "not firefox < 90", + "last 1 year", "not dead" ], "development": [ @@ -52,7 +49,7 @@ ] }, "engines": { - "node": ">=15.0.0" + "node": ">=22.0.0" }, "packageManager": "yarn@3.8.5" } diff --git a/src/Api/Strategies/pairCoversGroup.ts b/src/Api/Strategies/pairCoversGroup.ts index 37bdf4d9..fc18d35e 100644 --- a/src/Api/Strategies/pairCoversGroup.ts +++ b/src/Api/Strategies/pairCoversGroup.ts @@ -25,15 +25,15 @@ function _checkPair( // ^ group [sees A or B] [has A or B] // Avoid eliminating everything if (group_A.size === 0) { - const [groupIndex] = groupInfo(prop, [...group_A]) + const [groupIndex] = groupInfo(prop, group_A) window._custom.alert(`${prop} ${GRP_NAMES[prop][groupIndex]} has no possibilities for ${candidateA} !`) return "error" } // Condition 2: The two cells see all cells in the group that have A. - if (isSubset(group_A, affectsEitherAorB)) { + if (group_A.isSubsetOf(affectsEitherAorB)) { // Elimination type A - const [, allOfGroup, remaining] = groupInfo(prop, [...group_A]) + const [, allOfGroup, remaining] = groupInfo(prop, group_A) // Strategy does not work when X or Y is in the group if (allOfGroup.includes(cellA) || allOfGroup.includes(cellB)) { diff --git a/src/Api/Strategies/twoMinusOneLines.ts b/src/Api/Strategies/twoMinusOneLines.ts index 4df49bd7..cc86e64f 100644 --- a/src/Api/Strategies/twoMinusOneLines.ts +++ b/src/Api/Strategies/twoMinusOneLines.ts @@ -1,6 +1,6 @@ import { ALL_CANDIDATES, IndexToNine, INDICES_TO_NINE, SudokuDigits } from "../../Types"; import PureSudoku from "../Spaces/PureSudoku"; -import { affects, CellID, setDifference, sharedInArrays } from "../Utils"; +import { affects, CellID, sharedInArrays } from "../Utils"; import { colorGroup } from "../Utils.dependent"; import { __incrementMapValue } from "./skyscraper"; @@ -101,7 +101,7 @@ export function _innerGroupSubtractionLogic( if (successcount) { const nonExtraLineCells = __inLine(sumLines, nonExtraLine as IndexToNine, pendLineProp) - const extraCells = setDifference(sumLines, nonExtraLineCells) + const extraCells = sumLines.difference(nonExtraLineCells) colorGroup(sudoku, extraCells, candidate, "orange") colorGroup(sudoku, nonExtraLineCells, candidate) return { diff --git a/src/Api/Utils.ts b/src/Api/Utils.ts index 7d083fad..3ed4f7c6 100644 --- a/src/Api/Utils.ts +++ b/src/Api/Utils.ts @@ -168,22 +168,32 @@ export function getIDFromIndexWithinBox(indexOfBox: IndexToNine, indexInBox: Ind return id(boxRow * 3 + withinRow as IndexToNine, boxColumn * 3 + withinColumn as IndexToNine) } -export function groupInfo(type: GrpTyp, cells: CellID[]) { +function elementInIterable(iter: Iterable): T | undefined { + for (const elem of iter) { + return elem + } +} + +/** + * @param cells A nonempty iterable of `CellID` + */ +export function groupInfo(type: GrpTyp, cells: Iterable) { let groupIndex: IndexToNine let cellsInGroup + const arbitraryCell = elementInIterable(cells) as CellID // If it is undefined, it will error at runtime switch (type) { case "row": { - groupIndex = cells[0].row + groupIndex = arbitraryCell.row cellsInGroup = INDICES_TO_NINE.map(indice => id(groupIndex, indice)) break } case "column": { - groupIndex = cells[0].column + groupIndex = arbitraryCell.column cellsInGroup = INDICES_TO_NINE.map(indice => id(indice, groupIndex)) break } case "box": { - groupIndex = boxAt(cells[0].row, cells[0].column) + groupIndex = boxAt(arbitraryCell.row, arbitraryCell.column) cellsInGroup = INDICES_TO_NINE.map(indice => getIDFromIndexWithinBox(groupIndex, indice)) break } diff --git a/src/Elems/Version.tsx b/src/Elems/Version.tsx index a028fc79..27374702 100644 --- a/src/Elems/Version.tsx +++ b/src/Elems/Version.tsx @@ -9,7 +9,7 @@ import StaticComponent from './StaticComponent'; * */ function Version () { - return v0.36.1 + return v0.36.2 } export default StaticComponent(Version) diff --git a/yarn.lock b/yarn.lock index 4e45f7cb..e19a16bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3822,12 +3822,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.0.0": - version: 20.16.5 - resolution: "@types/node@npm:20.16.5" +"@types/node@npm:^22.0.0": + version: 22.5.5 + resolution: "@types/node@npm:22.5.5" dependencies: undici-types: ~6.19.2 - checksum: f38b7bd8c4993dcf38943afa2ffdd7dfd18fc94f8f3f28d0c1045a10d39871a6cc1b8f8d3bf0c7ed848457d0e1d283482f6ca125579c13fed1b7575d23e8e8f5 + checksum: 1f788966ff7df07add0af3481fb68c7fe5091cc72a265c671432abb443788ddacca4ca6378af64fe100c20f857c4d80170d358e66c070171fcea0d4adb1b45b1 languageName: node linkType: hard @@ -5335,17 +5335,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001259, caniuse-lite@npm:^1.0.30001272, caniuse-lite@npm:^1.0.30001280": - version: 1.0.30001651 - resolution: "caniuse-lite@npm:1.0.30001651" - checksum: c31a5a01288e70cdbbfb5cd94af3df02f295791673173b8ce6d6a16db4394a6999197d44190be5a6ff06b8c2c7d2047e94dfd5e5eb4c103ab000fca2d370afc7 - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001646": - version: 1.0.30001653 - resolution: "caniuse-lite@npm:1.0.30001653" - checksum: 289cf06c26a46f3e6460ccd5feffa788ab0ab35d306898c48120c65cfb11959bfa560e9f739393769b4fd01150c69b0747ad3ad5ec3abf3dfafd66df3c59254e +"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001259, caniuse-lite@npm:^1.0.30001272, caniuse-lite@npm:^1.0.30001280, caniuse-lite@npm:^1.0.30001646": + version: 1.0.30001662 + resolution: "caniuse-lite@npm:1.0.30001662" + checksum: 7a6a0c0d9f7c4a1c51de02838eb47f41f36fff57a77b846c8faed35ba9afba17b9399bc00bd637e5c1663cbc132534085d91151de48edca2ad8932a5d87e23af languageName: node linkType: hard @@ -13394,7 +13387,7 @@ resolve@^2.0.0-next.3: "@testing-library/react": ^12.1.2 "@testing-library/user-event": ^13.5.0 "@types/jest": ^27.0.2 - "@types/node": ^20.0.0 + "@types/node": ^22.0.0 "@types/react": ^17.0.34 "@types/react-dom": ^17.0.11 eslint-plugin-jest-dom: ^4.0.0