Skip to content

Commit 2917d2b

Browse files
committed
fix median
1 parent e138fa0 commit 2917d2b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/filters/filters.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ const filters = {
167167
if ((i >= window_size && i < ys.length) || extended) {
168168
if (centered) xs2.push(new Date(acc.x / acc.ys.length));
169169
else xs2.push(xs[i]);
170-
const mid1 = Math.floor(acc.ys.length / 2);
171-
const mid2 = Math.ceil(acc.ys.length / 2);
172-
ys2.push((acc.ys[mid1] + acc.ys[mid2]) / 2);
170+
const sorted = acc.ys.slice().sort();
171+
const mid1 = Math.floor(sorted.length / 2);
172+
const mid2 = Math.ceil(sorted.length / 2);
173+
ys2.push((sorted[mid1] + sorted[mid2]) / 2);
173174
}
174175
}
175176
return { ys: ys2, xs: xs2, ...rest };

0 commit comments

Comments
 (0)