From f1961a638fdd11eb4d1eb08a41655041acf3b01e Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Fri, 5 Apr 2024 01:16:05 -0400 Subject: [PATCH] segmentDaysByWeeks: use for loop, not forEach From suggestion https://github.com/e-mission/e-mission-phone/pull/1138#discussion_r1552388094 --- www/js/metrics/metricsHelper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/js/metrics/metricsHelper.ts b/www/js/metrics/metricsHelper.ts index 4fdb86c2d..8097e460f 100644 --- a/www/js/metrics/metricsHelper.ts +++ b/www/js/metrics/metricsHelper.ts @@ -35,15 +35,15 @@ export const secondsToHours = (seconds: number) => formatForDisplay(seconds / 36 export function segmentDaysByWeeks(days: DayOfMetricData[], lastDate: string) { const weeks: DayOfMetricData[][] = [[]]; let cutoff = isoDateWithOffset(lastDate, -7 * weeks.length); - [...days].reverse().forEach((d) => { - const date = dateForDayOfMetricData(d); + for (let i = days.length - 1; i >= 0; i--) { + const date = dateForDayOfMetricData(days[i]); // if date is older than cutoff, start a new week if (isoDatesDifference(date, cutoff) > 0) { weeks.push([]); cutoff = isoDateWithOffset(lastDate, -7 * weeks.length); } - weeks[weeks.length - 1].push(d); - }); + weeks[weeks.length - 1].push(days[i]); + } return weeks.map((week) => week.reverse()); }