UNPKG

@figliolia/data-structures

Version:

Efficient data structures for every day programming

31 lines (30 loc) 596 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stack = void 0; /** * Stack * * A basic stack with push, pop and peek methods * * ```typescript * import { Stack } from "@figliolia/data-structures"; * * const stack = new Stack<number>(); * stack.push(1); * stack.push(2); * stack.push(3); * stack.peek(); // 3 * stack.pop(); // 3 * ``` */ class Stack extends Array { /** * Peek * * Returns a reference to the first element in the stack */ peek() { return this[this.length - 1]; } } exports.Stack = Stack;