From 004b05fd507fffb2cd6ccf7d35b47aeb28965da7 Mon Sep 17 00:00:00 2001 From: Pete Corey Date: Mon, 8 Aug 2016 17:00:51 -0400 Subject: [PATCH] # Finishing the Transformation 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! --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a2181d1..5cb923a 100644 --- a/index.js +++ b/index.js @@ -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(); }