Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Todo Remove Reducer

Reducersmedium

Course · Section 17: Modern JavaScript Development: Modules, Tooling, and Functional · Lecture 294: Declarative and Functional JavaScript Principles

Implement `todoRemoveReducer(state, action)` where a `remove` action carries an `index`, removing that todo immutably.

Sample tests

Input: todoRemoveReducer([{"text":"a"},{"text":"b"}], {"type":"remove","index":0})
Output: [{"text":"b"}]
Input: todoRemoveReducer([{"text":"a"}], {"type":"remove","index":0})
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • splice mutates the array in place.

Learning resources

  • React: useReducer
Approach & explanation (try first)

filter builds a new array without the todo at the given index, leaving the original untouched.

Loading...
⌘/Ctrl + Enter

Run your code to see results.