Last active
April 18, 2021 07:46
-
-
Save dsibinski/38b88a48d8a5a715a3745bc4e6954c3c to your computer and use it in GitHub Desktop.
This file contains 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
export class DiscountApplier { | |
getDiscountPercentageValue(products: Product[]): number { | |
let discountValue = 0; | |
if (products.length === 1) { | |
return 0; | |
} | |
let allProductsQuantity = products.reduce((sum, product) => sum + product.quantity, 0); | |
if (allProductsQuantity > 10 && allProductsQuantity <= 50) { | |
discountValue += 10; | |
} | |
if (allProductsQuantity > 50) { | |
discountValue += 15; | |
} | |
let allProductsPrice = products.reduce((sum, product) => sum + product.quantity * product.price, 0); | |
if (allProductsPrice > 100 && allProductsPrice <= 500) { | |
discountValue += 5; | |
} | |
if (allProductsPrice > 500 && allProductsPrice <= 2000) { | |
discountValue += 10; | |
} | |
if (allProductsPrice > 2000) { | |
discountValue += 25; | |
} | |
return discountValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment