Skip to content

Instantly share code, notes, and snippets.

@ceci21
Created August 3, 2017 01:06
Show Gist options
  • Save ceci21/08a1b987096be90e6983696b22160055 to your computer and use it in GitHub Desktop.
Save ceci21/08a1b987096be90e6983696b22160055 to your computer and use it in GitHub Desktop.
Using a mathematical equation, calculates a coffee shop's profit based on the price of the first cup, refill price, cost to make coffee, and number of cups you get, plus how friendly you are with the cashier. Friendliness factor can only be values between 0 and 1.
function profit(firstCup, refillPrice, costToMake, numberOfCups, friendlinessFactor) {
return (
(-friendlinessFactor + 1) *
(Math.pow(numberOfCups, 0) * (firstCup - costToMake) +
Math.pow(numberOfCups, 0) * (refillPrice * (numberOfCups - 1) - costToMake * (numberOfCups - 1)))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment