Build the back and forward buttons of a single browser tab. Write a class TabHistory:
new TabHistory(homepage) opens the tab on homepage.visit(url) goes to url from the current page. Any pages you could have gone forward to are forgotten.back(steps) moves back up to steps pages (it stops at the first page) and returns the current URL.forward(steps) moves forward up to steps pages (it stops at the newest page) and returns the current URL.Each example lists the calls in order, then each call's arguments. The first call creates the object with new TabHistory(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["TabHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"] [["home.dev"],["docs.dev"],["blog.dev"],["shop.dev"],[1],[1],[1],["help.dev"],[2],[2],[7]] Output: [null,null,null,null,"blog.dev","docs.dev","blog.dev",null,"help.dev","docs.dev","home.dev"]
After going back twice to docs.dev and forward once to blog.dev, visiting help.dev forgets shop.dev, so forward(2) stays on help.dev.
Input: ["TabHistory","back","forward"] [["start.io"],[3],[3]] Output: [null,"start.io","start.io"]
With only the homepage, both buttons stay on start.io.
1 <= steps <= 1005000 calls in total.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #246 Tab History Navigator. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.