mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-27 00:04:37 +08:00
34 lines
756 B
JavaScript
34 lines
756 B
JavaScript
export function roundTo2(num) {
|
|
return Math.round((num + Number.EPSILON) * 100) / 100;
|
|
}
|
|
|
|
export function 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
|
|
);
|
|
}
|
|
|
|
export function mean(array) {
|
|
try {
|
|
return (
|
|
array.reduce((previous, current) => (current += previous)) / array.length
|
|
);
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export function kogasa(cov) {
|
|
return (
|
|
100 * (1 - Math.tanh(cov + Math.pow(cov, 3) / 3 + Math.pow(cov, 5) / 5))
|
|
);
|
|
}
|
|
|
|
export function identity(value) {
|
|
return Object.prototype.toString
|
|
.call(value)
|
|
.replace(/^\[object\s+([a-z]+)\]$/i, "$1")
|
|
.toLowerCase();
|
|
}
|