repositories
/
poolifier.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
3fa4cdd
)
perf: optimize median computation implementation
author
Jérôme Benoit
<jerome.benoit@sap.com>
Mon, 8 May 2023 23:09:53 +0000
(
01:09
+0200)
committer
Jérôme Benoit
<jerome.benoit@sap.com>
Mon, 8 May 2023 23:09:53 +0000
(
01:09
+0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils.ts
patch
|
blob
|
blame
|
history
diff --git
a/src/utils.ts
b/src/utils.ts
index 176d2c4f875fb2b3fc695ad419a8398d12467bb5..da1459f96be3877b3faf22913f548b920b4979e3 100644
(file)
--- a/
src/utils.ts
+++ b/
src/utils.ts
@@
-29,6
+29,9
@@
export const median = (dataSet: number[]): number => {
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]) /