@@ -48,14 +48,14 @@ export class CohortsController implements CohortsControllerType {
4848
4949 // Sort trainees in each group
5050 Object . values ( cohortDictionary ) . forEach ( ( trainees ) => {
51- trainees ?. sort ( this . compareTraineeInCohort ) ;
51+ trainees ?. sort ( this . compareTraineeInCohort . bind ( this ) ) ;
5252 } ) ;
5353 // Convert dictionary to array of cohorts
5454 const result : Cohort [ ] = Object . entries ( cohortDictionary ) . map ( ( [ cohortNumber , trainees ] ) => {
5555 const cohortNumberInt = Number . parseInt ( cohortNumber ) ;
5656 return {
5757 cohort : isNaN ( cohortNumberInt ) ? null : cohortNumberInt ,
58- trainees : ( trainees ?? [ ] ) . map ( this . getTraineeSummary ) ,
58+ trainees : ( trainees ?? [ ] ) . map ( this . getTraineeSummary . bind ( this ) ) ,
5959 } ;
6060 } ) ;
6161 res . status ( 200 ) . json ( result ) ;
@@ -76,16 +76,16 @@ export class CohortsController implements CohortsControllerType {
7676 LearningStatus : trainee . educationInfo . learningStatus ,
7777 JobPath : trainee . employmentInfo . jobPath ,
7878 strikes : trainee . educationInfo . strikes . length ,
79- averageTestScore : CohortsController . calculateAverageTestScore ( trainee . educationInfo . tests ) ,
79+ averageTestScore : this . calculateAverageTestScore ( trainee . educationInfo . tests ) ,
8080 } ;
8181 }
8282
83- private static calculateAverageTestScore ( tests : Test [ ] ) : number | null {
84- const testsWithScores = tests . filter ( ( test ) => test . score !== undefined && test . score !== null ) ;
83+ private calculateAverageTestScore ( tests : Test [ ] ) : number | null {
84+ const testsWithScores = tests . filter ( ( test ) => test . score !== undefined ) ;
8585 if ( testsWithScores . length === 0 ) {
8686 return null ;
8787 }
88- const sum = testsWithScores . reduce ( ( acc , test ) => acc + ( test . score as number ) , 0 ) ;
88+ const sum = testsWithScores . reduce ( ( acc , test ) => acc + ( test . score ?? 0 ) , 0 ) ;
8989 return sum / testsWithScores . length ;
9090 }
9191
0 commit comments