podcast-visualizer/window.ts

27 lines
417 B
TypeScript
Raw Permalink Normal View History

2020-06-06 22:19:36 +02:00
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;
}
}