-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: Combine array iterations in dashboard statistics #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,19 +130,20 @@ function updateStatistics(subjects) { | |
| return; | ||
| } | ||
|
|
||
| const scores = subjects.map(subject => subject.scoreValue); | ||
| const highest = Math.max(...scores); | ||
| let highest = -Infinity; | ||
|
|
||
| // 計算加權平均 | ||
| // 計算加權平均與最高分 (Combined loop for performance optimization) | ||
| let totalWeightedScore = 0; | ||
| let totalWeight = 0; | ||
|
|
||
| subjects.forEach(subject => { | ||
| for (const subject of subjects) { | ||
|
Comment on lines
+135
to
+139
|
||
| const score = subject.scoreValue; | ||
| if (score > highest) highest = score; | ||
|
|
||
|
Comment on lines
+139
to
+142
|
||
| const weight = getSubjectWeight(subject.SubjectName); | ||
| totalWeightedScore += score * weight; | ||
| totalWeight += weight; | ||
| }); | ||
| } | ||
|
|
||
| const weightedAvg = totalWeight > 0 ? totalWeightedScore / totalWeight : 0; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization of
highestto-Infinitychanges the behavior compared to the previousMath.max(...scores)implementation when dealing withNaNvalues. If all scores areNaN,Math.maxwould returnNaN, whereas this loop will leavehighestas-Infinity. This could result in the UI displaying "-Infinity" instead of "NaN" or a fallback value. Consider handlingNaNexplicitly or ensuring the display logic (outside this diff) handles-Infinitygracefully.