BeginnerCoder

Lesson 12 — Transform records

Filter, then total

Backend code often answers questions like "how much money did we actually receive?". That is two steps: filter keeps the paid orders, then reduce adds up their amounts. Chaining them reads left to right like a sentence.

orders.filter((o) => o.paid).reduce((s, o) => s + o.amount, 0);

Why it matters: this filter-then-sum pattern is behind most revenue numbers you will ever compute.

Want it another way?
Task

Compute paid (sum of paid orders) and unpaid (sum of the rest) and log both.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.