@gabrielrufino/cube
Version:
Data structures made in Typescript
75 lines (74 loc) • 2.84 kB
JavaScript
;
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 __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 Array = /** @class */ (function (_super) {
__extends(Array, _super);
function Array() {
var inputs = [];
for (var _i = 0; _i < arguments.length; _i++) {
inputs[_i] = arguments[_i];
}
return _super.call(this, inputs) || this;
}
Array.prototype.insertInLastPosition = function (element) {
this._data[this.size] = element;
return element;
};
Array.prototype.insertInFirstPosition = function (element) {
return this.insertInPosition(0, element);
};
Array.prototype.insertInPosition = function (position, element) {
this._data.splice(position, 0, element);
return element;
};
Array.prototype.removeFromLastPosition = function () {
var element = this._data[this.size - 1];
var array = new Array();
for (var i = 0; i < this.size - 1; i++) {
array.insertInLastPosition(this._data[i]);
}
this._data = array.data;
return element;
};
Array.prototype.removeFromFirstPosition = function () {
var element = this._data[0];
var array = new Array();
for (var i = 0; i < this.size - 1; i++) {
array.insertInLastPosition(this._data[i + 1]);
}
this._data = array.data;
return element;
};
Array.prototype.removeFromPosition = function (position) {
var element = this._data.splice(position, 1)[0];
return element;
};
Array.prototype[Symbol.toPrimitive] = function (type) {
var primitives = {
number: this.size,
string: this.data.join(', '),
default: true,
};
return primitives[type];
};
return Array;
}(DataStructure_1.default));
exports.default = Array;