I have an array containing objects of location and want the shortest point to a different point ie
//location array
let locations=[
{ x_axis:900, y_axis:900, },
{ x_axis:800, y_axis:800, },
{ x_axis:10, y_axis:40, },
{ x_axis:700, y_axis:700, },
];
let startPoint={ x_axis:0, y_axis:0, }
function closest(locations,startPoint){
//get closest point which is { x_axis:10, y_axis:40 }
}
What I tried using
const index_0 = locations.findIndex(
// Trash code but my aim was to get the closest locations object
// to mainPoint within 100 difference
item => item.x_axis - person[w].x_axis > -100,
item => item.x_axis > person[w].x_axis < 100,
item => item.y_axis - person[w].y_axis > -100,
item => item.y_axis > person[w].y_axis < 100,
);
console.log(locations[index_0])