Merge pull request #443 from Sushanth012/fix/case-sensitive-list-sort

fix(list): compare full strings in case-sensitive sort
This commit is contained in:
Chesterkxng authored and GitHub committed 2026-09-24 12:28:51 +02:00
commit ceaedcb1f0
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -60,7 +60,7 @@ function customAlphabeticSort(
return a.toLowerCase().localeCompare(b.toLowerCase());
} else {
// Case-sensitive comparison
return a.charCodeAt(0) - b.charCodeAt(0);
return a === b ? 0 : a < b ? -1 : 1;
}
}
@@ -183,6 +183,12 @@ describe('numericSort function', () => {
});
// CASE SENSITIVE TEST
it('should compare the full string when prefixes match', () => {
const result = alphabeticSort(['az', 'aa'], true, ',', false, true);
expect(result).toBe('aa,az');
});
it('should sort a list of string (uppercase) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'Pineaple', 'Lemon', 'Orange'];
const increasing: boolean = false;