From 0a09985ffa3e76c77b2cc097c962b103475717f0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 17 Jul 2026 06:40:11 +0000 Subject: [PATCH] refactor: simplify calculateMostActiveDay with modern array methods Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index d35c21bf..139d5323 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -90,19 +90,16 @@ function calculateStreaks(calendar: { count: number }[]): { longestStreak: numbe function calculateMostActiveDay(calendar: { date: string; count: number }[]): string | null { const weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - const weekdayTotals = Array.from({ length: 7 }, () => 0); - - for (const day of calendar) { - if (day.count === 0) { - continue; + const weekdayTotals = calendar.reduce((totals, day) => { + if (day.count > 0) { + totals[new Date(`${day.date}T00:00:00Z`).getUTCDay()] += day.count; } - const weekday = new Date(`${day.date}T00:00:00Z`).getUTCDay(); - weekdayTotals[weekday] += day.count; - } + return totals; + }, Array(7).fill(0)); const maxWeekdayTotal = Math.max(...weekdayTotals); return maxWeekdayTotal > 0 - ? weekdayNames[weekdayTotals.findIndex((count) => count === maxWeekdayTotal)] + ? weekdayNames[weekdayTotals.indexOf(maxWeekdayTotal)] : null; }