Skip to content

Commit

Permalink
Merge pull request openwebwork#2461 from Alex-Jordan/alphabetical
Browse files Browse the repository at this point in the history
case insensitive sorting by name
  • Loading branch information
drgrice1 authored Jul 30, 2024
2 parents e144640 + 7763e9d commit b38fcba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ sub sortByName ($field, @items) {
}

my @sKeys = sort {
return $a cmp $b if (uc($a) eq uc($b));

my @aParts = split m/(?<=\D)(?=\d)|(?<=\d)(?=\D)/, $a;
my @bParts = split m/(?<=\D)(?=\d)|(?<=\d)(?=\D)/, $b;

Expand All @@ -195,8 +197,8 @@ sub sortByName ($field, @items) {
next if $aPart == $bPart; # check next pair
return $aPart <=> $bPart; # compare numerically
} else {
next if $aPart eq $bPart; # check next pair
return $aPart cmp $bPart; # compare lexicographically
next if uc($aPart) eq uc($bPart); # check next pair
return uc($aPart) cmp uc($bPart); # compare alphabetically
}
}
return +1 if @aParts; # a has more sections, should go second
Expand Down

0 comments on commit b38fcba

Please sign in to comment.