Skip to content

Commit

Permalink
fix: median function fails if it receives an empty table (#316)
Browse files Browse the repository at this point in the history
* _median function fails if receive empty table.

* fix: median for 1 datapoint

Co-authored-by: Jérôme Wiedemann <jerome@wnetworks.org>
  • Loading branch information
lukasztackowiak and RomRider authored Apr 9, 2022
1 parent f2ef319 commit 12f8d2e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/graphEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ export default class GraphEntry {
private _median(items: EntityCachePoints) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const itemsDup = this._filterNulls([...items]).sort((a, b) => a[1]! - b[1]!);
if (itemsDup.length === 0) return null;
if (itemsDup.length === 1) return itemsDup[0][1];
const mid = Math.floor((itemsDup.length - 1) / 2);
if (itemsDup.length % 2 === 1) return itemsDup[mid][1];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down

0 comments on commit 12f8d2e

Please sign in to comment.