Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created March 7, 2017 04:23
Show Gist options
  • Save shaunlebron/bd705bc7626faac034c8956c64b068ec to your computer and use it in GitHub Desktop.
Save shaunlebron/bd705bc7626faac034c8956c64b068ec to your computer and use it in GitHub Desktop.
Optimizing cost on Turo
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