Skip to content

Instantly share code, notes, and snippets.

@dsibinski
Last active April 18, 2021 07:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsibinski/0f4fd7447abb8c4f65c47e93fccd3ee5 to your computer and use it in GitHub Desktop.
Save dsibinski/0f4fd7447abb8c4f65c47e93fccd3ee5 to your computer and use it in GitHub Desktop.
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