Last active
October 17, 2019 03:59
-
-
Save mushroomgead/b0e54760de411a78d4f3494a5be7f0b3 to your computer and use it in GitHub Desktop.
Company Challenges: Uber
This file contains 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
function checkIsUndefined(x) { | |
if (x.length === undefined) { | |
return 1 | |
} | |
return x.length | |
} | |
function fareEstimator(ride_time, ride_distance, cost_per_minute, cost_per_mile) { | |
let result = [] | |
let c_ride_time = checkIsUndefined(ride_time) | |
let c_ride_distance = checkIsUndefined(ride_distance) | |
let c_cost_per_minute = checkIsUndefined(cost_per_minute) | |
let c_cost_per_mile = checkIsUndefined(cost_per_mile) | |
let highestArr = Math.max(c_ride_time, c_ride_distance, c_cost_per_minute, c_cost_per_mile) | |
for (i = 0; i < highestArr; i++) { | |
result[i] = +(ride_time * cost_per_minute[i] + ride_distance * cost_per_mile[i]).toFixed(2) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment