File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,19 +130,23 @@ function updateStatistics(subjects) {
130130 return ;
131131 }
132132
133- const scores = subjects . map ( subject => subject . scoreValue ) ;
134- const highest = Math . max ( ...scores ) ;
135-
136- // 計算加權平均
133+ // Combine map, Math.max, and forEach into a single loop for performance
134+ let highest = - Infinity ;
137135 let totalWeightedScore = 0 ;
138136 let totalWeight = 0 ;
139137
140- subjects . forEach ( subject => {
138+ for ( let i = 0 ; i < subjects . length ; i ++ ) {
139+ const subject = subjects [ i ] ;
141140 const score = subject . scoreValue ;
141+
142+ if ( score > highest ) {
143+ highest = score ;
144+ }
145+
142146 const weight = getSubjectWeight ( subject . SubjectName ) ;
143147 totalWeightedScore += score * weight ;
144148 totalWeight += weight ;
145- } ) ;
149+ }
146150
147151 const weightedAvg = totalWeight > 0 ? totalWeightedScore / totalWeight : 0 ;
148152
You can’t perform that action at this time.
0 commit comments