Last active
October 16, 2019 03:05
-
-
Save mushroomgead/e51c26c7b157aa797a9a34d008002c38 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 fancyRide(l, fares) { | |
const uberLevel = ["UberX", "UberXL", "UberPlus", "UberBlack", "UberSUV"] | |
let result = [] | |
let posLevel = 0 | |
for (i = 0; i < fares.length; i++) { | |
result[i] = l * fares[i] | |
} | |
for (j = 0; j < result.length; j++) { | |
if (result[j] === 20) { | |
posLevel = j | |
} else if (result[result.length - 1] < 20) { | |
posLevel = j | |
} else if (20 > result[j] && 20 < result[j + 1]) { | |
posLevel = j | |
} | |
} | |
return uberLevel[posLevel] | |
} | |
fancyRide(15, [0.3, 0.5, 0.7, 1, 1.3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment