lik/dist/lik.limitedarray.js

40 lines
2.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class LimitedArray {
constructor(limitArg) {
this.array = [];
this.arrayLimit = limitArg;
}
addOne(objectArg) {
this.array.unshift(objectArg);
if (this.array.length > this.arrayLimit) {
this.array.length = this.arrayLimit;
}
}
addMany(objectArrayArg) {
for (let objectArg of objectArrayArg) {
this.addOne(objectArg);
}
}
setLimit(limitArg) {
this.arrayLimit = limitArg;
if (this.array.length > this.arrayLimit) {
this.array.length = this.arrayLimit;
}
}
getAverage() {
if (typeof this.array[0] === "number") {
let sum = 0;
for (let localNumber of this.array) {
let localNumberAny = localNumber;
sum = sum + localNumberAny;
}
return sum / this.array.length;
}
else {
return null;
}
}
}
exports.LimitedArray = LimitedArray;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLmxpbWl0ZWRhcnJheS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5saW1pdGVkYXJyYXkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFFQTtJQUdFLFlBQVksUUFBZ0I7UUFGNUIsVUFBSyxHQUFRLEVBQUUsQ0FBQztRQUdkLElBQUksQ0FBQyxVQUFVLEdBQUcsUUFBUSxDQUFDO0lBQzdCLENBQUM7SUFFRCxNQUFNLENBQUMsU0FBWTtRQUNqQixJQUFJLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQztRQUM5QixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUN4QyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDO1FBQ3RDLENBQUM7SUFDSCxDQUFDO0lBRUQsT0FBTyxDQUFD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