Skip to content

Instantly share code, notes, and snippets.

@reggie3
Created July 13, 2017 05:32
Show Gist options
  • Save reggie3/440348a2e780700591e3977eb979ffac to your computer and use it in GitHub Desktop.
Save reggie3/440348a2e780700591e3977eb979ffac to your computer and use it in GitHub Desktop.
Write distance results
case 'WRITE_DISTANCE_RESULTS':
return locations.map((location) => {
if (location.ID === action.ID) {
let distances = [action.distance].concat(location.distances);
distances = distances.slice(0, action.locationArrayMaxLength);
let distanceAverage = distances.reduce(function (sum, value) {
return sum + value;
}, 0) / distances.length;
return Object.assign({},
location,
{
distances,
distanceAverage
});
}
return location;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment