Problems

Todo Reducer

MediumContext & State Management

Implement a todo reducer. Actions, one JSON per line: {"type":"add","text":...}, {"type":"toggle","index":N}, {"type":"remove","index":N}. State starts empty; ids are assigned 1,2,3... Print the final state as JSON array of {id,text,done}.

Input: one action per line. Output: final todos JSON.

Your program reads from stdin and prints to stdout.

Example 1

Input: {"type":"add","text":"a"} {"type":"add","text":"b"} {"type":"toggle","index":0}

Output: [{"id":1,"text":"a","done":true},{"id":2,"text":"b","done":false}]

Hints

ReactReducersuseReducer
Todo Reducer | CodeForge AI