-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: resolve sort comparator and code quality issues (@ennajari) #7805
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
c8ea9f6
faa7bc4
0ef75ea
536aa2c
dffb721
c12b956
555b3f5
f469b6c
f963dda
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 |
|---|---|---|
|
|
@@ -132,4 +132,4 @@ frontend/static/webfonts-preview | |
| .turbo | ||
| frontend/.env.sentry-build-plugin | ||
| .claude/worktrees | ||
| 1024MiB | ||
| 1024MiB | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,8 @@ export function stdDev(array: number[]): number { | |
| const n = array.length; | ||
| const meanValue = mean(array); | ||
| return Math.sqrt( | ||
| array.map((x) => Math.pow(x - meanValue, 2)).reduce((a, b) => a + b) / n, | ||
| array.map((x) => Math.pow(x - meanValue, 2)).reduce((a, b) => a + b, 0) / | ||
|
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. I don't think this is needed.
Author
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. the surrounding |
||
| n, | ||
| ); | ||
| } catch (e) { | ||
| return 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.
I think we want consistent sorting here and not depend on the users locale.
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.
Changed to a locale-independent comparator:
(a, b) => (a < b ? -1 : a > b ? 1 : 0). Same for Sidebar.tsx and themes.ts.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.
Could you describe the difference between
and
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.
Honestly, there is no functional difference. For ASCII strings like theme/funbox names, both perform Unicode code-point comparison and produce identical results. The explicit comparator only satisfies the static analysis rule that requires a compare function to be provided, but the behavior is the same as plain
.sort().If you'd prefer, I can drop these three sort changes entirely — the two remaining fixes (
reduceinitial value and the!== undefinedcheck) still stand on their own.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.
If both do the same let's keep the simple
.sortThere 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.
Reverted all three sort changes back to plain
.sort(). The PR now only contains thereduceinitial value fix and the!== undefinedcache check.