refactor: improve stdDeviation signature
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 25 Aug 2023 10:42:29 +0000 (12:42 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 25 Aug 2023 10:42:29 +0000 (12:42 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/StatisticUtils.ts

index 3f587caaaf46c753d080b1cccc13fab131dacaba..ecd47a17f9af0b2d49601542ec3c8af78997d9dd 100644 (file)
@@ -64,10 +64,12 @@ export const nthPercentile = (dataSet: number[], percentile: number): number =>
   return sortedDataSet[percentileIndexInteger];
 };
 
-export const stdDeviation = (dataSet: number[], dataSetAverage?: number): number => {
-  dataSetAverage = dataSetAverage ?? average(dataSet);
+export const stdDeviation = (
+  dataSet: number[],
+  dataSetAverage: number = average(dataSet),
+): number => {
   const geometricDeviation = dataSet.reduce((accumulator, nb) => {
-    const deviation = nb - dataSetAverage!;
+    const deviation = nb - dataSetAverage;
     return accumulator + deviation * deviation;
   }, 0);
   return Math.sqrt(geometricDeviation / dataSet.length);