Design Browser History LeetCode solution in JavaScript
1var BrowserHistory = function (homepage) {2this.page = {3url: homepage,4back: null,5next: null,6};7};89BrowserHistory.prototype.visit = function (url) {10this.page.next = {11url,12back: this.page,13next: null,14};15this.page = this.page.next;16};1718BrowserHistory.prototype.back = function (steps) {19while (this.page.back && steps) {20this.page = this.page.back;21steps--;22}2324return this.page.url;25};2627BrowserHistory.prototype.forward = function (steps) {28while (this.page.next && steps) {29this.page = this.page.next;30steps--;31}3233return this.page.url;34};