repositories
/
e-mobility-charging-stations-simulator.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
637942e
)
perf: optimize median computation
author
Jérôme Benoit
<jerome.benoit@sap.com>
Mon, 8 May 2023 23:12:18 +0000
(
01:12
+0200)
committer
Jérôme Benoit
<jerome.benoit@sap.com>
Mon, 8 May 2023 23:12:18 +0000
(
01:12
+0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Utils.ts
patch
|
blob
|
blame
|
history
diff --git
a/src/utils/Utils.ts
b/src/utils/Utils.ts
index be372de697f43b384a6929a14884567fa23b72d0..f1d098cc9f8f1278f21e3793bf7799225a0f8e9e 100644
(file)
--- a/
src/utils/Utils.ts
+++ b/
src/utils/Utils.ts
@@
-344,6
+344,9
@@
export class Utils {
return dataSet[0];
}
const sortedDataSet = dataSet.slice().sort((a, b) => a - b);
+ if (sortedDataSet.length % 2 === 0) {
+ return sortedDataSet[sortedDataSet.length / 2];
+ }
return (
(sortedDataSet[(sortedDataSet.length - 1) >> 1] + sortedDataSet[sortedDataSet.length >> 1]) /
2