UNPKG

lgrthms

Version:

Algorithms and data structures for your JavaScript and TypeScript projects 🧑‍💻

27 lines (26 loc) 585 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stack = void 0; class Stack { constructor() { this.stack = []; } get size() { return this.stack.length; } // O(1) time | O(1) space push(value) { this.stack.push(value); return this.stack.length; } // O(1) time | O(1) space pop() { return this.stack.pop(); } // O(1) time | O(1) space peek() { const lastIndex = this.stack.length - 1; return this.stack[lastIndex]; } } exports.Stack = Stack;