Last active
July 30, 2020 10:44
-
-
Save andion/42060502aebe1eb6871ffb2ef83edc16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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