Last active
April 18, 2021 07:49
-
-
Save dsibinski/0f4fd7447abb8c4f65c47e93fccd3ee5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; | |
} | |
// ...... | |
// The rest of business logic related to quantity/price/value of the products bought | |
return discountValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment