UNPKG

@figliolia/data-structures

Version:

Efficient data structures for every day programming

27 lines (26 loc) 479 B
/** * 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 * ``` */ export class Stack extends Array { /** * Peek * * Returns a reference to the first element in the stack */ peek() { return this[this.length - 1]; } }