Easy JavaScript with Comments
\nvar nearestValidPoint = function(x, y, points) {\n    var distance=Infinity;  //To keep track of smallest distance found\n    var index=-1;   //To keep track 
```\nvar nearestValidPoint = function(x, y, points) {\n    var distance=Infinity;  //To keep track of smallest distance found\n    var index=-1;   //To keep track of index\n    for(let i=0;i<points.length;i++){\n        //If points are valid\n        if(points[i][0]==x || points[i][1]==y){ \n            //Calutating the current distance\n            let current_distance=Math.abs(points[i][0]-x) + Math.abs(points[i][1]-y);   \n            //If current distance is less than smallest distance found till now then we update the index and distance value\n            if(current_distance<distance)\n                {\n                    distance=current_distance;\n                    index=i;\n                }\n        }\n    }\n    //If no point is found we by default return -1\n    return index;  \n};\n```
[]