From 8f60746ca1192bfcab03d890016a4704703a701a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 15 Sep 2023 22:08:51 +0200 Subject: [PATCH] refactor: cleanup standard deviation implementation 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/StatisticUtils.ts b/src/utils/StatisticUtils.ts index ecd47a17..7f338ff9 100644 --- a/src/utils/StatisticUtils.ts +++ b/src/utils/StatisticUtils.ts @@ -68,9 +68,9 @@ export const stdDeviation = ( dataSet: number[], dataSetAverage: number = average(dataSet), ): number => { - const geometricDeviation = dataSet.reduce((accumulator, nb) => { - const deviation = nb - dataSetAverage; - return accumulator + deviation * deviation; - }, 0); - return Math.sqrt(geometricDeviation / dataSet.length); + return Math.sqrt( + dataSet.reduce((accumulator, num) => { + return accumulator + Math.pow(num - dataSetAverage, 2); + }, 0) / dataSet.length, + ); }; -- 2.34.1