Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passed all tests #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the logic here, you can levage the the distanceFromHqInBlocks function:

Suggested change
if(destination > 42){
return (destination - 42) * 264
}
else{
return (42 - destination) * 264
}
distanceFromHqInBlocks(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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}
const distance = start > destination ? (start - destination) * 264 : (destination - start) * 264
if(distance <= 400 ){
return 0;
}else if(distance < 2000){
return .02 * (distance - 400);
}else if(distance > 2500){
return 'cannot travel that far'
}else if(distance > 2000){
return 25;
}

}