Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Use median to filter out extreme positions to compute more appropriate region
const lowMiddle = Math.floor((distances.length - 1) / 2);
const highMiddle = Math.ceil((distances.length - 1) / 2);
const median = (distances[lowMiddle].distance + distances[highMiddle].distance) / 2;
const validDistances =
distances.length > 2
? distances
.filter(({ distance }) => median * 1.5 > distance)
.slice(0, NO_OF_MARKERS_IN_REGION)
: distances;
const coordsByDistance = validDistances
.map(({ key }) => coordinates[parseInt(key, 10)])
.filter(Boolean);
const boundaries = getBounds(coordsByDistance);
const latitudeDelta = boundaries.maxLat - boundaries.minLat;
const longitudeDelta = boundaries.maxLng - boundaries.minLng;
return { longitudeDelta, latitudeDelta };
};