Added module example

This commit is contained in:
didier amyot committed 2023-11-30 12:27:37 -05:00
commit a3f4ca664f
4 files changed
+46

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
export function average(lst){
if(lst.length < 1){
return NaN;
}
let sum = 0;
let n = 0;
for(const e of lst){
sum += e;
n += 1;
}
return sum / n;
}
export function std(lst){
if(lst.length < 1){
return NaN;
}
let sum = 0;
let sum2 = 0;
let n = 0;
for(const e of lst){
sum += e;
sum2 += e * e;
n += 1;
}
return Math.sqrt( sum2 / n - Math.pow(sum / n, 2));
}