From 0715bba0dfbfc882bd6762a3305dd72cc29875fd Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Tue, 2 Apr 2024 21:11:07 +0200 Subject: [PATCH] Fix reduce on empty array --- src/main.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 29f6097..b7c4d93 100644 --- a/src/main.ts +++ b/src/main.ts @@ -289,11 +289,10 @@ async function buildMarkerMap(bulletins: AvalancheBulletin[]) { popup.show(e.coordinate, formatBulletin(regionID, bulletin)); return; } - const aws = eawsOutlineProperties - .filter((p) => regionID.startsWith(p.id)) - .reduce((a, b) => (a.id.length > b.id.length ? a : b)); - if (aws) { - popup.show(e.coordinate, formatEawsOutline(aws)); + const aws = eawsOutlineProperties.filter((p) => regionID.startsWith(p.id)); + if (aws.length) { + const a = aws.reduce((a, b) => (a.id.length > b.id.length ? a : b)); + popup.show(e.coordinate, formatEawsOutline(a)); return; } });