From 82e0fba507f2147db7b24dc3b9172cd3afc994f1 Mon Sep 17 00:00:00 2001 From: braddf Date: Fri, 14 Jul 2023 15:43:30 +0100 Subject: [PATCH] Add empty array check to centredMovingAvg func --- lib/graphs.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/graphs.ts b/lib/graphs.ts index a99e3fc..3af2282 100644 --- a/lib/graphs.ts +++ b/lib/graphs.ts @@ -172,6 +172,9 @@ export const calculateCenteredMovingAverage = ( points: GenerationDataPoint[], period: number ): GenerationDataPoint[] => { + if (points.length === 0) { + return []; + } if (period % 2 == 0) { throw new Error('Period must be an odd number'); } else if (period > points.length) {