I am using several selectors to get the boundaries on which to set my Google Maps. They basically return the lowest and highest lat/lng points from the data. The code works but I feel this is really messy and can be re-factored, but i'm not too sure how.
Here is the code:
const getMinLat = data =>
data.reduce((prev, current) => {
return prev.coords[0] < current.coords[0] ? prev : current
})
const getMaxLat = data =>
data.reduce((prev, current) => {
return prev.coords[0] > current.coords[0] ? prev : current
})
const getMinLng = data =>
data.reduce((prev, current) => {
return prev.coords[1] < current.coords[1] ? prev : current
})
const getMaxLng = data =>
data.reduce((prev, current) => {
return prev.coords[1] > current.coords[1] ? prev : current
})
const getBounds = data => [
{
lat: getMinLat(data).coords[0],
lng: getMinLng(data).coords[1],
},
{
lat: getMaxLat(data).coords[0],
lng: getMaxLng(data).coords[1],
},
]