Created
March 7, 2017 04:23
-
-
Save shaunlebron/bd705bc7626faac034c8956c64b068ec to your computer and use it in GitHub Desktop.
Optimizing cost on Turo
This file contains hidden or 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 turoMiles(desiredMiles) { | |
var costPerDay = 35; | |
var costPerMileOver = 0.75; | |
var milesPerDay = 150; | |
var milesPerWeek = 1000; | |
function milesAllowed(days) { | |
var weeks = Math.floor(days / 7); | |
days = days % 7; | |
return weeks*milesPerWeek + days*milesPerDay; | |
} | |
var entries = []; | |
for (var days=5; days<=11; days++) { | |
var limit = milesAllowed(days); | |
var overage = Math.max(0, desiredMiles - limit); | |
var cost = days*costPerDay + overage*costPerMileOver; | |
entries.push({ | |
days: days, | |
limit: limit, | |
overage: overage, | |
cost: cost, | |
}); | |
} | |
console.table(entries); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment