You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
417 B
TypeScript
27 lines
417 B
TypeScript
export default class Window {
|
|
length: number;
|
|
buffer: number[] = [];
|
|
constructor(length: number) {
|
|
this.length = length;
|
|
}
|
|
|
|
push(element: number) {
|
|
if (this.buffer.length == this.length) {
|
|
this.buffer.shift();
|
|
}
|
|
this.buffer.push(element);
|
|
}
|
|
|
|
sum() {
|
|
return this.buffer.reduce((a, b) => a + b, 0);
|
|
}
|
|
|
|
clear() {
|
|
this.buffer = [];
|
|
}
|
|
|
|
isFull() {
|
|
return this.buffer.length == this.length;
|
|
}
|
|
}
|