Easy to understand JavaScript solution (reduce)
\tvar nearestValidPoint = function(x, y, points) {\n\t\tconst valid = points.reduce((acc, [pointX, pointY], index) => {\n\t\t\tif (x === pointX || y === pointY)
\tvar nearestValidPoint = function(x, y, points) {\n\t\tconst valid = points.reduce((acc, [pointX, pointY], index) => {\n\t\t\tif (x === pointX || y === pointY) {\n\t\t\t\tconst distance = Math.abs(x - pointX) + Math.abs(y - pointY);\n\n\t\t\t\tdistance < acc.distance && (acc = { distance, index });\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, { distance: Infinity, index: -1 });\n\n\t\treturn valid.index;\n\t};
['JavaScript']