function average (locations) {
  if (!Array.isArray(locations) || locations.length === 0) {
    return null
  }

  const first = locations[0]
  const latitude = avg(locations.map(getLatitude))
  const longitude = avg(locations.map(getLongitude))

  return createLocation(latitude, longitude, getLocationType(first))
}
/**
 * Calculate the average of a list with locations
 * @param {Location[]} locations 
 * @return {Location} Returns the average location or null when the list is empty
 *                    Location has the same structure as the first location from
 *                    the input array.
 */
Calculate the average of a list with locations
@param {Location[]} locations
@return {Location} Returns the average location or null when the list is empty
Location has the same structure as the first location from
the input array.
Calculate the average of a list with locations @param { Location [] } locations @return { Location } Returns the average location or null when the list is empty Location has the same structure as the first location from the input array .
function average (locations) {
  if (!Array.isArray(locations) || locations.length === 0) {
    return null
  }
  const first = locations[0]
  const latitude = avg(locations.map(getLatitude))
  const longitude = avg(locations.map(getLongitude))
  return createLocation(latitude, longitude, getLocationType(first))
}
function average ( locations ) { if ( ! Array . isArray ( locations ) || locations . length === 0 ) { return null } const first = locations [ 0 ] const latitude = avg ( locations . map ( getLatitude ) ) const longitude = avg ( locations . map ( getLongitude ) ) return createLocation ( latitude , longitude , getLocationType ( first ) ) }
Calculate the average of a list with locations
 @param {Location[]} locations
 @return {Location} Returns the average location or null when the list is empty
                    Location has the same structure as the first location from
                    the input array.
Calculate the average of a list with locations @param { Location [] } locations @return { Location } Returns the average location or null when the list is empty Location has the same structure as the first location from the input array .