We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 508c69e commit 3c90160Copy full SHA for 3c90160
src/helpers/calc.ts
@@ -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