File tree 1 file changed +13
-9
lines changed 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -45,17 +45,21 @@ export function groupsByUserId(organizationId: string) {
45
45
}
46
46
}
47
47
48
- for ( const groupsList of userIdMapper . values ( ) ) {
49
- groupsList . sort ( ( g1 , g2 ) => {
50
- const key =
51
- g1 . display_name && g2 . display_name ? "display_name" : "name" ;
48
+ // Defined outside the loop because it can be reused by all group arrays,
49
+ // and doesn't need to be rebuilt from scratch on each iteration
50
+ const orderGroupsByName = ( g1 : Group , g2 : Group ) => {
51
+ const key =
52
+ g1 . display_name && g2 . display_name ? "display_name" : "name" ;
53
+
54
+ if ( g1 [ key ] === g2 [ key ] ) {
55
+ return 0 ;
56
+ }
52
57
53
- if ( g1 [ key ] === g2 [ key ] ) {
54
- return 0 ;
55
- }
58
+ return g1 [ key ] < g2 [ key ] ? - 1 : 1 ;
59
+ } ;
56
60
57
- return g1 [ key ] < g2 [ key ] ? - 1 : 1 ;
58
- } ) ;
61
+ for ( const groupsList of userIdMapper . values ( ) ) {
62
+ groupsList . sort ( orderGroupsByName ) ;
59
63
}
60
64
61
65
return userIdMapper as GroupsByUserId ;
You can’t perform that action at this time.
0 commit comments