added mean function

This commit is contained in:
Miodec 2022-01-07 16:24:45 +01:00
parent 296bdc56ff
commit 1231e6bc9b

View file

@ -9,4 +9,14 @@ module.exports = {
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n
);
},
mean(array) {
try {
return (
array.reduce((previous, current) => (current += previous)) /
array.length
);
} catch (e) {
return 0;
}
},
};