UNPKG

@kartikkhk/stl-node

Version:

Standard Data Structures for Node JS

31 lines (30 loc) 635 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Queue { constructor(arr) { this._arr = []; if (Array.isArray(arr)) this._arr = Array.from(arr); } add(value) { this._arr.push(value); } peek() { if (this.isEmpty()) return undefined; return this._arr[0]; } remove() { return this._arr.shift(); } isEmpty() { return this._arr.length === 0; } array() { return this._arr; } static fromArray(array) { return new Queue(array); } } exports.default = Queue;