From d3bef89e10fae1d042d80a7cbb960f58c4485b95 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Mon, 6 May 2024 11:56:48 -0400 Subject: [PATCH 1/3] Passed all tests --- index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/index.js b/index.js index 0db6949168..0206896441 100644 --- a/index.js +++ b/index.js @@ -1 +1,40 @@ // Code your solution in this file! +function distanceFromHqInBlocks(destination){ + if(destination > 42){ + return destination - 42 + } + else{ + return 42 - destination + } +} + +function distanceFromHqInFeet(destination){ + if(destination > 42){ + return (destination - 42) * 264 + } + else{ + return (42 - destination) * 264 + } +} + +function distanceTravelledInFeet(start, destination){ + if(start > destination){ + return (start - destination) * 264 + } else{ + return (destination - start) * 264 + } +} + +function calculatesFarePrice(start, destination){ + //Destination in feet + const distance = start > destination ? (start - destination) * 264 : (destination - start) * 264 + if(distance <= 400 ){ + return 0; + }else if(distance > 400 && distance < 2000){ + return .02 * (distance-400); + }else if(distance > 2500){ + return 'cannot travel that far' + }else if(distance > 2000){ + return 25; + } +} From 5e8502ea6181b6a686bcf0286791f86ba4776334 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Tue, 7 May 2024 11:14:05 -0400 Subject: [PATCH 2/3] Refactor functions --- index.js | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 0206896441..f59d763692 100644 --- a/index.js +++ b/index.js @@ -1,40 +1,27 @@ // Code your solution in this file! function distanceFromHqInBlocks(destination){ - if(destination > 42){ - return destination - 42 - } - else{ - return 42 - destination - } + return Math.abs(destination - 42) } function distanceFromHqInFeet(destination){ - if(destination > 42){ - return (destination - 42) * 264 - } - else{ - return (42 - destination) * 264 - } + return Math.abs(distanceFromHqInBlocks(destination) * 264) } function distanceTravelledInFeet(start, destination){ - if(start > destination){ - return (start - destination) * 264 - } else{ - return (destination - start) * 264 - } + return Math.abs((start - destination) * 264) } function calculatesFarePrice(start, destination){ //Destination in feet - const distance = start > destination ? (start - destination) * 264 : (destination - start) * 264 + // const distance = start > destination ? (start - destination) * 264 : (destination - start) * 264 + const distance = distanceTravelledInFeet(start, destination) if(distance <= 400 ){ return 0; - }else if(distance > 400 && distance < 2000){ - return .02 * (distance-400); - }else if(distance > 2500){ - return 'cannot travel that far' - }else if(distance > 2000){ + }else if(distance < 2000){ + return .02 * (distance - 400); + }else if(distance < 2500){ return 25; + }else{ + return 'cannot travel that far' } } From 25e1ea093207a21513125f7f54c186408b702259 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Tue, 7 May 2024 11:15:12 -0400 Subject: [PATCH 3/3] Remove comments --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index f59d763692..03d179ff25 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -// Code your solution in this file! function distanceFromHqInBlocks(destination){ return Math.abs(destination - 42) } @@ -12,8 +11,6 @@ function distanceTravelledInFeet(start, destination){ } function calculatesFarePrice(start, destination){ - //Destination in feet - // const distance = start > destination ? (start - destination) * 264 : (destination - start) * 264 const distance = distanceTravelledInFeet(start, destination) if(distance <= 400 ){ return 0;