lik/dist/lik.limitedarray.js

40 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-09-21 20:54:22 +00:00
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLmxpbWl0ZWRhcnJheS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5saW1pdGVkYXJyYXkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFFQTtJQUdFLFlBQVksUUFBZ0I7UUFGNUIsVUFBSyxHQUFRLEVBQUUsQ0FBQTtRQUdiLElBQUksQ0FBQyxVQUFVLEdBQUcsUUFBUSxDQUFBO0lBQzVCLENBQUM7SUFFRCxNQUFNLENBQUUsU0FBWTtRQUNsQixJQUFJLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQTtRQUM3QixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUN4QyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFBO1FBQ3JDLENBQUM7SU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