Easy to understand
``\nvar queensAttacktheKing = function(queens, king) {\n  const map = {};\n  queens.forEach(q => map[q.join(\',\')] = 1);\n  \n  // for eight directions, find t
```\nvar queensAttacktheKing = function(queens, king) {\n  const map = {};\n  queens.forEach(q => map[q.join(\',\')] = 1);\n  \n  // for eight directions, find the first queen\n  const ans = [];\n  const dirs = [[1, 0], [0, 1], [-1, 0], [0, -1], [-1, 1], [1, -1], [1, 1], [-1, -1]];\n  // record if needed to go further for each direction\n  const visited = new Array(8).fill(false);\n  let step = 1;\n  while (step < 8) {\n    dirs.forEach((d, i) => {\n      if (!visited[i]) {\n        let x = king[0] + step * d[0];\n        let y = king[1] + step * d[1];\n        if (x < 0 || y < 0 || x > 7 || y > 7) {\n          visited[i] = true;\n        } else if (map[`${x},${y}`]) {\n          visited[i] = true;\n          ans.push([x, y]);\n        }\n      }\n    });\n    step += 1;\n  }\n  \n  return ans;\n};
['JavaScript']