aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/helpers.ts
blob: 673c8fbd9fba8deefd276b606ef66d9b4f67fa1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 }
}