Skip to content

Commit

Permalink
Refactoring: bulletingsByRegionID
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Nov 16, 2024
1 parent 270d279 commit 2046ea8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ async function buildMap(bulletins: AvalancheBulletin[], date: string) {
new Style({ fill: new Fill({ color }), zIndex: warnLevelNumber }),
]),
);
const bulletingsByRegionID = Object.fromEntries(
bulletins.flatMap(b => (b.regions??[]).map(r => [r.regionID, b]))
)
const style = ({
id,
elevation,
threshold,
}: MicroRegionElevationProperties): Style => {
const dangerRatings =
bulletins.find((b) => b.regions?.some((r) => r.regionID === id))
?.dangerRatings ?? [];
const dangerRatings = bulletingsByRegionID[id]?.dangerRatings?? [];
if (
elevation === "high" &&
dangerRatings
Expand Down

0 comments on commit 2046ea8

Please sign in to comment.