From 44ff6231441024d16fddc2b7cb648539522b04cb Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Mon, 19 Dec 2022 21:04:23 +0100 Subject: v1.0.0 Added everything that's in the spec --- src/lib/helpers.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/lib/helpers.ts (limited to 'src/lib/helpers.ts') 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 } +} -- cgit v1.3.1