Course · Section 17: Modern JavaScript Development: Modules, Tooling, and Functional · Lecture 294: Declarative and Functional JavaScript Principles
Implement `cartReducer(state, action)` where state is an array of `{ id, qty }`: - `{ type: 'add', id }` increments qty or appends `{ id, qty: 1 }`. - `{ type: 'setQty', id, qty }` sets the quantity. - `{ type: 'remove', id }` removes the line. All immutable.
+ 1 hidden test run on Submit.
The reducer handles each cart action immutably, the pattern behind a useReducer-managed cart.
Run your code to see results.