export const getTheNearestLocation = (locations, currentPoint) => {
if (locations.length === 0) {
return null;
}
let [nearestLocation] = locations;
const [, nearestPoint] = nearestLocation;
let lowestDistance = getDistance(currentPoint, nearestPoint);
for (const location of locations) {
const [, point] = location;
const distance = getDistance(currentPoint, point);
if (distance < lowestDistance) {
lowestDistance = distance;
nearestLocation = location;
}
}
return nearestLocation;
};