Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- discountPrice2(totalPrice) {
- let percentage = 0;
- if (totalPrice >= 1000 && totalPrice < 5000) {
- percentage = 3;
- } else if (totalPrice >= 5000 && totalPrice < 7000) {
- percentage = 5;
- } else if (totalPrice >= 7000 && totalPrice < 10000) {
- percentage = 7;
- } else if (totalPrice >= 10000 && totalPrice < 50000) {
- percentage = 10;
- } else if (totalPrice >= 50000) {
- percentage = 15;
- } else {
- percentage = 0;
- }
- return this.subtractPercentage(totalPrice, percentage);
- }
- discountPrice(totalPrice) {
- const ranges = [
- [1000, 5000, 3],
- [5000, 7000, 5],
- [7000, 10000, 7],
- [10000, 50000, 10],
- [50000, Number.MAX_SAFE_INTEGER, 15]
- ];
- for (let i = 0; i < ranges.length; i++) {
- if (totalPrice < 1000) {
- return this.subtractPercentage(totalPrice, 0);
- } else if (totalPrice >= ranges[i][0] && totalPrice <= ranges[i][1]) {
- return this.subtractPercentage(totalPrice, ranges[i][2]);
- break;
- }
- }
- }
- subtractPercentage(number, percentage) {
- number = parseFloat(number);
- return number - number / 100 * percentage;
- }
Add Comment
Please, Sign In to add comment