Skip to content

Instantly share code, notes, and snippets.

@LukeberryPi
Last active December 19, 2023 01:04

Revisions

  1. LukeberryPi revised this gist Dec 19, 2023. No changes.
  2. LukeberryPi created this gist Dec 18, 2023.
    11 changes: 11 additions & 0 deletions areAdjacent.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    function areAdjacent(coord1, coord2) {
    const [x1, y1] = coord1;
    const [x2, y2] = coord2;

    const isHorizontallyAdjacent = Math.abs(x1 - x2) === 1 && y1 === y2;
    const isVerticallyAdjacent = x1 === x2 && Math.abs(y1 - y2) === 1;
    const isDiagonallyAdjacent =
    Math.abs(x1 - x2) === 1 && Math.abs(y1 - y2) === 1;

    return isHorizontallyAdjacent || isVerticallyAdjacent || isDiagonallyAdjacent;
    }