Swedish Tipping
Description:
In Sweden, tipping at restaurants is not done in a straight-forward 15-20% of the bill manner.
Instead, people use a heuristic that "Rounds Up" to the next significant amount.
For example, in America, if you got a bill for $100 you might tip $17 on it, since $100 % .17 = $17. In Sweden, you'd probably tip 20
for a nice round amount of 120
. We're going to skip the currency formatting and deal only with the Number type for convenience and so we can focus on the meaty part of the problem.
The goal of this exercise is to build an algorithm that comes up with a good default tip amount to put in our application's UI.
What people think of as "significant" varies from human to human, but when developing your heuristic keep these things in mind:
- Sweden has 1, 5, and 10kr coins; and bills for 20, 50, and 100kr; although the 50 isn't used very often.
- You should return the tip amount, not the total amount.
- You should never tip less than 5%. That would be super rude.
Example outputs:
getSwedishTip(1); // 9, since 1+9 === 10. This is similar to the "never tip less than a dollar" US pseudo-rule.
getSwedishTip(88); // 12, since 88+12 === 100. Round up to a nice even amount
getSwedishTip(1021); // 79 (79+1021 === 1100). Round up to a nice, even amount but with larger bills
One thing to note is that as the bill gets more expensive, the idea of what is "siginificant" for rounding up changes.
Don't forget about IEEE float representation rounding issues. Our application wants a suggestedd value for the UI, so exactly accurate currency math (eg: bankers rounding) is not necessary, but repeating digits are not acceptable.
getSwedishTip(8.2) // return 1.8, not 1.8000000000000007
You can return any amount >=
5% for bills larger than 10000
or so. If our app is processing orders like that we have new and high-quality problems.
Similar Kata:
Stats:
Created | Oct 4, 2016 |
Published | Oct 4, 2016 |
Warriors Trained | 63 |
Total Skips | 19 |
Total Code Submissions | 208 |
Total Times Completed | 11 |
JavaScript Completions | 11 |
Total Stars | 1 |
% of votes with a positive feedback rating | 83% of 6 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |