-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: Combine multiple O(n) array operations into a single loop #129
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,23 @@ function updateStatistics(subjects) { | |
| return; | ||
| } | ||
|
|
||
| const scores = subjects.map(subject => subject.scoreValue); | ||
| const highest = Math.max(...scores); | ||
|
|
||
| // 計算加權平均 | ||
| // 計算加權平均與最高分,合併迴圈以提升效能 | ||
| let totalWeightedScore = 0; | ||
| let totalWeight = 0; | ||
| let highest = -Infinity; | ||
|
|
||
| subjects.forEach(subject => { | ||
| for (let i = 0; i < subjects.length; i++) { | ||
| const subject = subjects[i]; | ||
| const score = subject.scoreValue; | ||
|
|
||
| if (score > highest) { | ||
| highest = score; | ||
| } | ||
|
Comment on lines
+136
to
+144
|
||
|
|
||
| const weight = getSubjectWeight(subject.SubjectName); | ||
| totalWeightedScore += score * weight; | ||
| totalWeight += weight; | ||
| }); | ||
| } | ||
|
Comment on lines
+138
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While a standard for (const subject of subjects) {
const score = subject.scoreValue;
if (score > highest) {
highest = score;
}
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.
PR 描述提到已用
pnpm test驗證,但此 repo 的package.json只有npm test(node --test ...)腳本且看起來未使用 pnpm。請更新 PR 描述的測試指令或補充實際執行的命令,以免後續維護者依描述操作失敗。