monkeytype/backend/handlers/misc.js

23 lines
495 B
JavaScript
Raw Normal View History

module.exports = {
roundTo2(num) {
return Math.round((num + Number.EPSILON) * 100) / 100;
},
stdDev(array) {
const n = array.length;
const mean = array.reduce((a, b) => a + b) / n;
return Math.sqrt(
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n
);
2021-07-07 21:03:46 +08:00
},
2022-01-07 23:24:45 +08:00
mean(array) {
try {
return (
array.reduce((previous, current) => (current += previous)) /
array.length
);
} catch (e) {
return 0;
}
},
2021-07-07 21:03:46 +08:00
};