diff --git a/dist/index.d.ts b/dist/index.d.ts index 6775686..407fed9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,3 +2,4 @@ export * from './lik.looptracker'; export * from './lik.objectmap'; export * from './lik.observablemap'; export * from './lik.stringmap'; +export * from './lik.limitedarray'; diff --git a/dist/index.js b/dist/index.js index 2ee714a..d819ca8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8,4 +8,5 @@ __export(require("./lik.looptracker")); __export(require("./lik.objectmap")); __export(require("./lik.observablemap")); __export(require("./lik.stringmap")); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLGlCQUFpQjtBQUVqQix1Q0FBaUM7QUFDakMscUNBQStCO0FBQy9CLHlDQUFtQztBQUNuQyxxQ0FBK0IifQ== \ No newline at end of file +__export(require("./lik.limitedarray")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLGlCQUFpQjtBQUVqQix1Q0FBaUM7QUFDakMscUNBQStCO0FBQy9CLHlDQUFtQztBQUNuQyxxQ0FBK0I7QUFDL0Isd0NBQWtDIn0= \ No newline at end of file diff --git a/dist/lik.limitedarray.d.ts b/dist/lik.limitedarray.d.ts new file mode 100644 index 0000000..d3c95d8 --- /dev/null +++ b/dist/lik.limitedarray.d.ts @@ -0,0 +1,9 @@ +export declare class LimitedArray { + array: T[]; + arrayLimit: number; + constructor(limitArg: number); + addOne(objectArg: T): void; + addMany(objectArrayArg: T[]): void; + setLimit(limitArg: number): void; + getAverage(): number; +} diff --git a/dist/lik.limitedarray.js b/dist/lik.limitedarray.js new file mode 100644 index 0000000..a9308a2 --- /dev/null +++ b/dist/lik.limitedarray.js @@ -0,0 +1,40 @@ +"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLmxpbWl0ZWRhcnJheS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5saW1pdGVkYXJyYXkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFFQTtJQUdFLFlBQVksUUFBZ0I7UUFGNUIsVUFBSyxHQUFRLEVBQUUsQ0FBQTtRQUdiLElBQUksQ0FBQyxVQUFVLEdBQUcsUUFBUSxDQUFBO0lBQzVCLENBQUM7SUFFRCxNQUFNLENBQUUsU0FBWTtRQUNsQixJQUFJLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQTtRQUM3QixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUN4QyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxDQU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0FBeENELG9DQXdDQyJ9 \ No newline at end of file diff --git a/test/test.limitedarray.ts b/test/test.limitedarray.ts new file mode 100644 index 0000000..1c48144 --- /dev/null +++ b/test/test.limitedarray.ts @@ -0,0 +1,17 @@ +import { tap, expect } from 'tapbundle' + +import { LimitedArray } from '../ts/index' + +let testLimitedArray: LimitedArray + +tap.test('should create a LimitedArray', async () => { + testLimitedArray = new LimitedArray(6) + expect(testLimitedArray).to.be.instanceof(LimitedArray) +}) + +tap.test('should never be longer than the set length', async () => { + testLimitedArray.addMany(['hi','this','is','quite','a','long','string',':)']) + expect(testLimitedArray.array.length).to.be.lessThan(7) +}) + +tap.start() diff --git a/test/test.looptracker.ts b/test/test.looptracker.ts index f75fc6d..805e042 100644 --- a/test/test.looptracker.ts +++ b/test/test.looptracker.ts @@ -5,7 +5,7 @@ import * as rx from 'rxjs/Rx' import * as smartq from 'smartq' // import the module -import lik = require('../ts/index') +import * as lik from '../ts/index' let object1 = {} let object2 = {} diff --git a/test/test.objectmap.ts b/test/test.objectmap.ts index 772a5b8..3e9eeb3 100644 --- a/test/test.objectmap.ts +++ b/test/test.objectmap.ts @@ -5,7 +5,7 @@ import * as rx from 'rxjs/Rx' import * as smartq from 'smartq' // import the module -import lik = require('../ts/index') +import * as lik from '../ts/index' // Objectmap interface ITestObject { diff --git a/test/test.observablemap.ts b/test/test.observablemap.ts index f905d40..79a312f 100644 --- a/test/test.observablemap.ts +++ b/test/test.observablemap.ts @@ -5,7 +5,7 @@ import * as rx from 'rxjs/Rx' import * as smartq from 'smartq' // import the module -import lik = require('../ts/index') +import * as lik from '../ts/index' let testObservablemap: lik.Observablemap let testObservable1: rx.Observable diff --git a/test/test.stringmap.ts b/test/test.stringmap.ts index 933f8bb..c1282b6 100644 --- a/test/test.stringmap.ts +++ b/test/test.stringmap.ts @@ -5,7 +5,7 @@ import * as rx from 'rxjs/Rx' import * as smartq from 'smartq' // import the module -import lik = require('../ts/index') +import * as lik from '../ts/index' // testData let testStringmap: lik.Stringmap diff --git a/ts/index.ts b/ts/index.ts index a5427b7..6f85d2a 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -6,3 +6,4 @@ export * from './lik.looptracker' export * from './lik.objectmap' export * from './lik.observablemap' export * from './lik.stringmap' +export * from './lik.limitedarray' diff --git a/ts/lik.limitedarray.ts b/ts/lik.limitedarray.ts new file mode 100644 index 0000000..86ed1e6 --- /dev/null +++ b/ts/lik.limitedarray.ts @@ -0,0 +1,43 @@ +import * as plugins from './lik.plugins' + +export class LimitedArray { + array: T[] = [] + arrayLimit: number + constructor(limitArg: number) { + this.arrayLimit = limitArg + } + + addOne (objectArg: T) { + this.array.unshift(objectArg) + if (this.array.length > this.arrayLimit) { + this.array.length = this.arrayLimit + } + } + + addMany (objectArrayArg: T[]) { + for (let objectArg of objectArrayArg) { + this.addOne(objectArg) + } + } + + setLimit (limitArg: number) { + this.arrayLimit = limitArg + if (this.array.length > this.arrayLimit) { + this.array.length = this.arrayLimit + } + } + + getAverage ():number { + if (typeof this.array[0] === 'number') { + let sum = 0 + for (let localNumber of this.array) { + let localNumberAny: any = localNumber + sum = sum + localNumberAny + } + return sum / this.array.length + } else { + return null + } + } + +} diff --git a/ts/lik.stringmap.ts b/ts/lik.stringmap.ts index 47f8b24..5c6f4b2 100644 --- a/ts/lik.stringmap.ts +++ b/ts/lik.stringmap.ts @@ -100,7 +100,7 @@ export class Stringmap { ) this.notifyTrigger() } - + /** * notifies triggers */