MOBILE-3320 core: Always pass initial value to reduce function

main
Dani Palou 2021-06-30 08:12:19 +02:00
parent b36051d5d0
commit a3b35a9619
3 changed files with 10 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import {
AddonModAssignSubmission, AddonModAssignSubmission,
AddonModAssignProvider, AddonModAssignProvider,
AddonModAssign, AddonModAssign,
AddonModAssignGrade,
} from '../../services/assign'; } from '../../services/assign';
import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../../services/assign-helper'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../../services/assign-helper';
import { AddonModAssignOffline } from '../../services/assign-offline'; import { AddonModAssignOffline } from '../../services/assign-offline';
@ -252,7 +253,10 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro
// Get the last grade of the submission. // Get the last grade of the submission.
const grade = grades const grade = grades
.filter((grade) => grade.userid == submission.userid) .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),
<AddonModAssignGrade | undefined> undefined,
);
if (grade && grade.timemodified < submission.timemodified) { if (grade && grade.timemodified < submission.timemodified) {
submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT; submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT;

View File

@ -190,7 +190,10 @@ export class AddonModLessonOfflineProvider {
const attempts = await this.getRetakeAttemptsForPage(lessonId, retake, retakeData.lastquestionpage, siteId); const attempts = await this.getRetakeAttemptsForPage(lessonId, retake, retakeData.lastquestionpage, siteId);
// Return the attempt with highest timemodified. // 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,
<AddonModLessonPageAttemptRecord | undefined> undefined,
);
} catch { } catch {
// Error, return undefined. // Error, return undefined.
} }

View File

@ -632,7 +632,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
const completionModules = (<CoreCourseModule[]> []) const completionModules = (<CoreCourseModule[]> [])
.concat(...this.sections!.map((section) => section.modules)) .concat(...this.sections!.map((section) => section.modules))
.map((module) => module.completion && module.completion > 0 ? 1 : module.completion) .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); const moduleProgressPercent = 100 / (completionModules || 1);
// Use min/max here to avoid floating point rounding errors over/under-flowing the progress bar. // Use min/max here to avoid floating point rounding errors over/under-flowing the progress bar.