Given these:
const cart = [
{
products: [
{ price: 65 },
{ price: 30 }
]
},
{
products: [
{ price: 15 },
{ price: 25 }
]
}
]
Solution:
const totalPrice = cart.reduce((accumulator, item) => {
const productSum = item.products.reduce((productAcc, product) => {
return productAcc + product.price;
}, 0);
return accumulator + productSum;
}, 0);
Top comments (0)