From 981b2ca568651a1db2fd6628538d233e76f88bb1 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Mon, 11 Apr 2022 14:08:35 -0400 Subject: [PATCH] hack: Generalize geom mean to negative values... by falling back to the arithmetic mean if there are any --- lib/findPaths.js | 4 ++-- lib/utils.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/findPaths.js b/lib/findPaths.js index b44dd50..7f20757 100644 --- a/lib/findPaths.js +++ b/lib/findPaths.js @@ -4,7 +4,7 @@ import { numToAlphabeticalString, formatLargeOrSmall, avg, - geomMean, + hackyGeomMean, } from "../lib/utils.js"; /* Functions */ @@ -315,7 +315,7 @@ export function CreateTable({ tableRows }) { {abridgeArrayAndDisplay(row.distances)}     - {formatLargeOrSmall(geomMean(row.distances))} + {formatLargeOrSmall(hackyGeomMean(row.distances))} ))} diff --git a/lib/utils.js b/lib/utils.js index d9af918..5d48779 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -102,6 +102,15 @@ export const geomMean = (arr) => { return result; }; +export const hackyGeomMean = (arr) => { + let nonPositiveNumbers = arr.filter((x) => x <= 0); + if (nonPositiveNumbers.length == 0) { + return geomMean(arr); + } else { + return avg(arr); + } +}; + export function conservativeNumMergeSortSteps(n) { return Math.ceil((expectedNumMergeSortSteps(n) + maxMergeSortSteps(n)) / 2); }