Skip to content

Instantly share code, notes, and snippets.

@andion
Last active July 30, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andion/42060502aebe1eb6871ffb2ef83edc16 to your computer and use it in GitHub Desktop.
Save andion/42060502aebe1eb6871ffb2ef83edc16 to your computer and use it in GitHub Desktop.
const totalDistance = waypoints => waypoints.map(w => calculateDistance(w)).reduce((acc, d) => acc + d, 0);
/* Average velocity in m/s between any (consecutive) waypoints */
const avgVelocity = wayPoints => {
if(wayPoints.length < 2) {
return 0;
}
const first = wayPoints[0];
const [last] = wayPoints.slice(-1);
const elapsedTime = last.time - first.time;
return totalDistance(wayPoints) / elapsedTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment