JSFiddle - React, Tailwind, and code Playground
JavaScript
class Akku {
constructor(){
this.total = 0n;
this.count = 0n;
}
get average(){
return this.total / this.count;
}
add(value){
this.total += BigInt(value);
this.count += 1n;
}
addAll(x){
for(const v of x)
this.add(v);
}
}
const array = new Array(1000).fill(0).map(()=>Math.random()*1000+0.5|0);
const akku = new Akku();
akku.addAll(array);
document.writeln(akku.average);