const products = [
{name: 'Laptop', price: 1000},
{name: 'Mobile', price: 500},
{name: 'TV', price: 2000},
{name: 'Camera', price: undefined}
]
function sumPriceProducts() {
return products.reduce((acc, product) => {
return acc + (product.price || 0);
}, 0);
}
let soma = sumPriceProducts()
console.log(soma);
Top comments (0)