Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- groupBy(x=>x.Cart)
- .aggregate(g => {
- var products = g.values.reduce((agg, item) => {
- for (var key in item.Products) {
- var p = item.Products[key];
- var existing = agg[key];
- if (!existing) {
- agg[key] = { Quantity: p.Quantity, Price: p.Price };
- }
- else {
- existing.Quantity += p.Quantity;
- if(p.Price > 0)
- existing.Price = Math.min(p.Price, existing.Price);
- }
- }
- return agg;
- }, {});
- for (var key in products) {
- if(products[key].Quantity == 0)
- delete products[key];
- }
- return {
- Cart: g.key,
- Products: products
- };
- })
Add Comment
Please, Sign In to add comment