From 975d0a94addc4d30b75b05c3a2ff39baa5017d9d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 25 Aug 2023 12:42:29 +0200 Subject: [PATCH] refactor: improve stdDeviation signature MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/StatisticUtils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); -- 2.34.1