From 637942ee11115a833f48e24634d0014ebe5b9a8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 May 2023 00:36:53 +0200 Subject: [PATCH] refactor: cleanup statistic helpers code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 4f89179f..be372de6 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -343,8 +343,11 @@ export class Utils { if (Array.isArray(dataSet) === true && dataSet.length === 1) { return dataSet[0]; } - dataSet = dataSet.slice().sort((a, b) => a - b); - return (dataSet[(dataSet.length - 1) >> 1] + dataSet[dataSet.length >> 1]) / 2; + const sortedDataSet = dataSet.slice().sort((a, b) => a - b); + return ( + (sortedDataSet[(sortedDataSet.length - 1) >> 1] + sortedDataSet[sortedDataSet.length >> 1]) / + 2 + ); } // TODO: use order statistics tree https://en.wikipedia.org/wiki/Order_statistic_tree -- 2.34.1