JSFiddle - React, Tailwind, and code Playground

by Vatsal Pande

JavaScript

// Given an array of products, find the total cost of products that cost more than $500.

const products = [
  { name: "Laptop", price: 1200 },
  { name: "Phone", price: 800 },
  { name: "Monitor", price: 300 },
  { name: "Mouse", price: 50 }
];

function totalExpensiveProducts(products) {
  return products.reduce((acc, curr) => {
		if (curr.price > 500) {
    	acc = acc +curr.price

    }
      return acc;    
  },0)
}

console.log(totalExpensiveProducts(products));