Skip to content

Commit 3c90160

Browse files
committed
add helpers
1 parent 508c69e commit 3c90160

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/helpers/calc.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const calculateMean = (values: number[]) => values.reduce((acc, val) => acc + val, 0) / values.length;
2+
3+
export const calculateVolatility = (values: number[]) => {
4+
if (values.length === 0) {
5+
throw new Error('Cannot calculate volatility for empty array');
6+
}
7+
8+
const mean = calculateMean(values);
9+
const meanAbsoluteDeviationFps = values.reduce((acc, val) => acc + Math.abs(val - mean), 0) / values.length;
10+
return (meanAbsoluteDeviationFps * 100) / mean;
11+
};

0 commit comments

Comments
 (0)