Skip to content

Instantly share code, notes, and snippets.

@mushroomgead
Last active October 17, 2019 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mushroomgead/b0e54760de411a78d4f3494a5be7f0b3 to your computer and use it in GitHub Desktop.
Save mushroomgead/b0e54760de411a78d4f3494a5be7f0b3 to your computer and use it in GitHub Desktop.
Company Challenges: Uber
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