Undo and redo
Implement undoable(reducer). It returns a reducer over { past, present, future }. { type: 'undo' } moves present to the front of future and the last past state to present. { type: 'redo' } does the reverse. Any other action goes to the inner reducer: when it returns a new present, push the old one onto past and clear future; when it returns the same present, return the same state. With nothing to undo or redo, return the same state. Called with an undefined state, start with empty past and future and the inner reducer's own initial state. In the tests the inner reducer is a counter starting at 0 (inc, and add with by); same tells whether the last action returned the same reference.
Start from
function undoable(reducer) {
// Return a reducer over { past, present, future }.
}Hints and solution
Solve it in the app: its tests run without a year.
The hints, the solution and what an interviewer looks for opens with a year in the app. What a year includes