Find Nearest Point That Has the Same X or Y Coordinate LeetCode solution in JavaScript
1var nearestValidPoint = function (x, y, points) {2let min = Infinity;3let idx = -1;4points.forEach(([a, b], i) => {5if (a === x || b === y) {6const dist = Math.abs(x - a) + Math.abs(y - b);7if (dist < min) {8idx = i;9min = dist;10}11}12});13return idx;14};