From: Jérôme Benoit Date: Fri, 25 Aug 2023 10:42:29 +0000 (+0200) Subject: refactor: improve stdDeviation signature X-Git-Tag: v1.2.21~66 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=975d0a94addc4d30b75b05c3a2ff39baa5017d9d;p=e-mobility-charging-stations-simulator.git refactor: improve stdDeviation signature Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/StatisticUtils.ts b/src/utils/StatisticUtils.ts index 3f587caa..ecd47a17 100644 --- a/src/utils/StatisticUtils.ts +++ b/src/utils/StatisticUtils.ts @@ -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);