aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/helpers.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-12-19 21:04:23 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-12-19 21:04:23 +0100
commit44ff6231441024d16fddc2b7cb648539522b04cb (patch)
tree8302d0734f4ce931631ffe6d43af5b9a5da284a0 /src/lib/helpers.ts
parent9f4618c5ef618521ce1ab680d82ed9cc941d10d8 (diff)
downloaddigit-single-44ff6231441024d16fddc2b7cb648539522b04cb.tar.gz
digit-single-44ff6231441024d16fddc2b7cb648539522b04cb.tar.zst
digit-single-44ff6231441024d16fddc2b7cb648539522b04cb.zip
v1.0.0
Added everything that's in the spec
Diffstat (limited to 'src/lib/helpers.ts')
-rw-r--r--src/lib/helpers.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts
new file mode 100644
index 0000000..673c8fb
--- /dev/null
+++ b/src/lib/helpers.ts
@@ -0,0 +1,16 @@
+import type { Coord } from "./Sudoku";
+
+export function getNewCoord(direction: string, curCoords: Coord) {
+ let { x, y } = curCoords;
+ if (direction === "up")
+ x === 0 ? x = 8 : x--;
+ else if (direction === "down")
+ x === 8 ? x = 0 : x++;
+ else if (direction === "right")
+ y === 8 ? y = 0 : y++;
+ else if (direction === "left")
+ y === 0 ? y = 8 : y--;
+ else
+ throw new Error("getNewCoord(): bad direction")
+ return { x, y }
+}