x y plane coordinates – find is how many points in the list above are located a distance less than or equal to the radius [closed]

I’ll show you a decent way to go about doing this problem, but you need to implement the logic yourself

var pts = [{x:-33,y:83},{x:81,y:-99},{x:-13,y:-89},{x:13,y:-22},{x:-17,y:55},{x:78,y:-96}, {x:77,y:99},{x:-81,y:27}];

var allowedDistance = 40;
var pt = {x: 0, y: 0}; //the radius point the user provides

let validPts = pts.filter(function (currPt){
    let distance = //use formula here to calculate distance between pt and currPt
    return //return true if the distance is within your allowed distance otherwise false
});

console.log(validPts); //or validPts.length if you just want to know how many points are within allowedDistance

Leave a Comment