I'm currently working on a small Angular project that involves managing an array of receipt items such as Coke, Fanta, Pepsi, Juice, etc. Each receipt item has its own price and quantity listed.
receiptItems: Array<ReceiptItem>;
Here is the structure of the ReceiptItem
class:
export class ReceiptItem {
public id: string;
public product: Product;
public unitOfMeasure: UnitOfMeasure;
public discount: number;
public price: number;
public quantity: number;
public total: number;
public tax:Tax;
}
I am wondering how I can calculate the sum of total amounts for items where the tax property is equal to "25%" in TypeScript.
In C#, I have previously used lambda expressions like the following:
IEnumerable<ReceiptItems> results = receiptItems.Where(s => s.Tax == "25.00");
totalSum = results.Sum(x => (x.TotalAmount));
Is there a way to achieve a similar functionality in TypeScript / Angular?