Course · Section 17: Modern JavaScript Development: Modules, Tooling, and Functional · Lecture 294: Declarative and Functional JavaScript Principles
Totals should be derived from cart items during render, not kept in separate state. Implement `cartSummary(items)` where each item is `{ price, qty }`, returning `{ count, subtotal }` — the total quantity and total price.
+ 1 hidden test run on Submit.
Derived values are computed from the source of truth on every render, so they cannot fall out of sync. A reduce accumulates the quantity and the per-line price * qty into a single summary object.
Run your code to see results.