Skip to content

Commit

Permalink
# Finishing the Transformation
Browse files Browse the repository at this point in the history
Now that we have all of the pieces of our transformation we can refactor
our `distance` function.

The basic idea is that we want to split our the lat/lon of each
coordinate, convert those DMS coordinates to a decimal format, pass the
resulting coordinates into `haversine` and then rounding the result.

After doing this refactoring, our tests still pass!
  • Loading branch information
pcorey committed Aug 8, 2016
1 parent 3ae294c commit 004b05f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -28,5 +28,13 @@ export function haversine(lat1, lon1, lat2, lon2, R) {
}

export function distance(coord1, coord2) {
return 0;
return _.chain([coord1, coord2])
.map(splitOnLatLon)
.flatten()
.map(toDecimal)
.thru(([lat1, lon1, lat2, lon2]) => haversine(lat1, lon1, lat2, lon2, 6371))
.divide(10)
.floor()
.multiply(10)
.value();
}

0 comments on commit 004b05f

Please sign in to comment.