Skip to content

Instantly share code, notes, and snippets.

@mushroomgead
Last active October 16, 2019 03:05
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/e51c26c7b157aa797a9a34d008002c38 to your computer and use it in GitHub Desktop.
Save mushroomgead/e51c26c7b157aa797a9a34d008002c38 to your computer and use it in GitHub Desktop.
Company Challenges: Uber
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