JavaScript and TypeScript Clean Code
JavaScript:\njs\nconst dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];\nconst WALKED = \'-\', WALL = \'+\', NO_EXIT = -1;\n\n/**\n * @param {character[][]} maze\n * @
JavaScript:\n```js\nconst dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];\nconst WALKED = \'-\', WALL = \'+\', NO_EXIT = -1;\n\n/**\n * @param {character[][]} maze\n * @param {number[]} entrance\n * @return {number}\n */\nvar nearestExit = function(maze, entrance) {\n  const m = maze.length, n = maze[0].length;\n  const [ey, ex] = entrance;\n  maze[ey][ex] = WALKED;\n  \n  const queue = new Queue([[ey, ex, 0]]);\n  while (queue.size()) {\n    const [y, x, step] = queue.dequeue();\n    \n    for (const [dy, dx] of dir) {\n      const ny = y + dy, nx = x + dx, nextStep = step + 1;\n      const overBorder = ny < 0 || ny >= m || nx < 0 || nx >= n;\n      if (overBorder) {\n        continue;\n      }\n      if (maze[ny][nx] === WALKED || maze[ny][nx] === WALL) {\n        continue;\n      }\n      const isExit = ny === 0 || ny === m - 1 || nx === 0 || nx === n - 1;\n      if (isExit) {\n        return nextStep;\n      }\n      \n      maze[ny][nx] = WALKED;\n      queue.enqueue([ny, nx, nextStep]);\n    }\n  }\n  \n  return NO_EXIT;\n};\n\n```\n\nTypeScript:\n```js\nconst dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];\nconst WALKED = \'-\', WALL = \'+\', NO_EXIT = -1;\n\nfunction nearestExit(maze: string[][], entrance: number[]): number {\n  const m = maze.length, n = maze[0].length;\n  const [ey, ex] = entrance;\n  maze[ey][ex] = WALKED;\n  \n  const queue = new Queue([[ey, ex, 0]]);\n  while (queue.size()) {\n    const [y, x, step] = queue.dequeue();\n    \n    for (const [dy, dx] of dir) {\n      const ny = y + dy, nx = x + dx, nextStep = step + 1;\n      const overBorder = ny < 0 || ny >= m || nx < 0 || nx >= n;\n      if (overBorder) {\n        continue;\n      }\n      if (maze[ny][nx] === WALKED || maze[ny][nx] === WALL) {\n        continue;\n      }\n      const isExit = ny === 0 || ny === m - 1 || nx === 0 || nx === n - 1;\n      if (isExit) {\n        return nextStep;\n      }\n      \n      maze[ny][nx] = WALKED;\n      queue.enqueue([ny, nx, nextStep]);\n    }\n  }\n  \n  return NO_EXIT;\n};\n\n```\n
['TypeScript', 'JavaScript']