UNPKG

@gabrielrufino/cube

Version:

Data structures made in Typescript

76 lines (75 loc) 2.89 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var DataStructure_1 = __importDefault(require("../DataStructure")); var Deck = /** @class */ (function (_super) { __extends(Deck, _super); function Deck() { var inputs = []; for (var _i = 0; _i < arguments.length; _i++) { inputs[_i] = arguments[_i]; } return _super.call(this, inputs) || this; } Deck.prototype.addFront = function (element) { this._data = __spreadArray([element], this.data, true); return element; }; Deck.prototype.addBack = function (element) { this._data = __spreadArray(__spreadArray([], this.data, true), [element], false); return element; }; Deck.prototype.removeFront = function () { var _a = this.data, element = _a[0], rest = _a.slice(1); this._data = rest; return element; }; Deck.prototype.removeBack = function () { var element = this._data.pop(); return element; }; Deck.prototype.peekFront = function () { var element = this.data[0]; return element; }; Deck.prototype.peekBack = function () { var element = this.data[this.size - 1]; return element; }; Deck.prototype[Symbol.toPrimitive] = function (type) { var primitives = { number: this.size, string: "[Front] ".concat(this.data.join(', '), " [Back]"), default: true, }; return primitives[type]; }; return Deck; }(DataStructure_1.default)); exports.default = Deck;