1.Total of paid orders
BeginnerPrint the total amount of the orders whose status is "paid".
Show hint
filter the paid orders, then reduce to a sum starting at 0.
Show solution
const orders = [
{ id: 1, customer: "Asha", amount: 499, status: "paid" },
{ id: 2, customer: "Ravi", amount: 1200, status: "pending" },
{ id: 3, customer: "Asha", amount: 250, status: "paid" },
{ id: 4, customer: "Meera", amount: 80, status: "cancelled" },
];
const total = orders
.filter((o) => o.status === "paid")
.reduce((sum, o) => sum + o.amount, 0);
console.log(total);749