Step 3 of 4

Put it back

You start from the build so far — your own work where you have written it, the reference build where you have not. Either way this step stands on its own.

Redo is undo read backwards, and it is why undo kept the command rather than throwing it away.

History.redo() pops the newest command off undone, applies it again, and pushes it back onto done.

insert("hello")   ->  "hello"
remove(3)         ->  "he"
undo()            ->  "hello"
redo()            ->  "he"

Redoing with nothing undone does nothing, for the same reason undo does.

Notice that Remove being reapplied captures what it removes all over again. That is not an accident of this implementation — a command that recorded its effect only once could not be replayed against a document that had changed.

Your build

Running is free — Submit is what records the step. Or press ⌘↩

Tests

4 cases, 1 hidden
calltypeexpectedresult
runOps([["insert","ab"],["undo"],["redo"]])redo re-applies what was undone["ab","","ab"]
runOps([["insert","hello"],["remove",3],["undo"],["redo"]])redoing a removal removes again["hello","he","hello","he"]
runOps([["insert","a"],["redo"]])redo with nothing undone does nothing["a","a"]
withheldhiddenwithheld

Hidden cases run too — their inputs aren't listed here, so aim for a general solution rather than one fitted to the cases above.

Hints

Stuck? Hints open one at a time, each giving a little more away.

3 hints left