feat(collections): add new collection APIs, iterator support, and tree serialization utilities

This commit is contained in:
2026-03-22 08:44:49 +00:00
parent 20182a00f8
commit f4db131ede
23 changed files with 2251 additions and 2657 deletions

View File

@@ -7,6 +7,10 @@ export class LimitedArray<T> {
this.arrayLimit = limitArg;
}
public get length(): number {
return this.array.length;
}
addOne(objectArg: T) {
this.array.unshift(objectArg);
if (this.array.length > this.arrayLimit) {
@@ -28,6 +32,9 @@ export class LimitedArray<T> {
}
getAverage(): number {
if (this.array.length === 0) {
return 0;
}
if (typeof this.array[0] === 'number') {
let sum = 0;
for (let localNumber of this.array) {
@@ -39,4 +46,25 @@ export class LimitedArray<T> {
return null;
}
}
remove(item: T): boolean {
const idx = this.array.indexOf(item);
if (idx !== -1) {
this.array.splice(idx, 1);
return true;
}
return false;
}
clear(): void {
this.array.length = 0;
}
getArray(): T[] {
return [...this.array];
}
public [Symbol.iterator](): Iterator<T> {
return this.array[Symbol.iterator]();
}
}