From a3b35a961996747e13286e9c10b8bacb3e723f21 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 30 Jun 2021 08:12:19 +0200 Subject: [PATCH] MOBILE-3320 core: Always pass initial value to reduce function --- .../assign/pages/submission-list/submission-list.page.ts | 6 +++++- src/addons/mod/lesson/services/lesson-offline.ts | 5 ++++- src/core/features/course/components/format/format.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/addons/mod/assign/pages/submission-list/submission-list.page.ts b/src/addons/mod/assign/pages/submission-list/submission-list.page.ts index 5cfd6de5b..911bbbba0 100644 --- a/src/addons/mod/assign/pages/submission-list/submission-list.page.ts +++ b/src/addons/mod/assign/pages/submission-list/submission-list.page.ts @@ -29,6 +29,7 @@ import { AddonModAssignSubmission, AddonModAssignProvider, AddonModAssign, + AddonModAssignGrade, } from '../../services/assign'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../../services/assign-helper'; import { AddonModAssignOffline } from '../../services/assign-offline'; @@ -252,7 +253,10 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro // Get the last grade of the submission. const grade = grades .filter((grade) => grade.userid == submission.userid) - .reduce((a, b) => (a.timemodified > b.timemodified ? a : b)); + .reduce( + (a, b) => (a && a.timemodified > b.timemodified ? a : b), + undefined, + ); if (grade && grade.timemodified < submission.timemodified) { submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT; diff --git a/src/addons/mod/lesson/services/lesson-offline.ts b/src/addons/mod/lesson/services/lesson-offline.ts index 4a4297372..626ed383b 100644 --- a/src/addons/mod/lesson/services/lesson-offline.ts +++ b/src/addons/mod/lesson/services/lesson-offline.ts @@ -190,7 +190,10 @@ export class AddonModLessonOfflineProvider { const attempts = await this.getRetakeAttemptsForPage(lessonId, retake, retakeData.lastquestionpage, siteId); // Return the attempt with highest timemodified. - return attempts.reduce((a, b) => a.timemodified > b.timemodified ? a : b); + return attempts.reduce( + (a, b) => a && a.timemodified > b.timemodified ? a : b, + undefined, + ); } catch { // Error, return undefined. } diff --git a/src/core/features/course/components/format/format.ts b/src/core/features/course/components/format/format.ts index e03ca79a2..a76e10358 100644 --- a/src/core/features/course/components/format/format.ts +++ b/src/core/features/course/components/format/format.ts @@ -632,7 +632,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { const completionModules = ( []) .concat(...this.sections!.map((section) => section.modules)) .map((module) => module.completion && module.completion > 0 ? 1 : module.completion) - .reduce((accumulator, currentValue) => (accumulator || 0) + (currentValue || 0)); + .reduce((accumulator, currentValue) => (accumulator || 0) + (currentValue || 0), 0); const moduleProgressPercent = 100 / (completionModules || 1); // Use min/max here to avoid floating point rounding errors over/under-flowing the progress bar.