chore: sync remaining local changes to Gitea
This commit is contained in:
20
test-sort-siblings.js
Normal file
20
test-sort-siblings.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// 测试 compareByBirthName 排序
|
||||
|
||||
const members = [
|
||||
{ id: 'de8e2fc8', name: '唐雪', birthYear: 1990, gender: '女' },
|
||||
{ id: '08a22bcd', name: '唐波', birthYear: 1990, gender: '男' }
|
||||
];
|
||||
|
||||
function compareByBirthName(a, b) {
|
||||
if (a.birthYear !== b.birthYear) return b.birthYear - a.birthYear;
|
||||
return a.name.localeCompare(b.name, 'zh-Hans-CN');
|
||||
}
|
||||
|
||||
const sorted = members.slice().sort(compareByBirthName);
|
||||
console.log('排序前:', members.map(m => m.name).join(', '));
|
||||
console.log('排序后:', sorted.map(m => m.name).join(', '));
|
||||
|
||||
// 测试中文姓名比较
|
||||
console.log('\n中文比较:');
|
||||
console.log('唐波 vs 唐雪:', '唐波'.localeCompare('唐雪', 'zh-Hans-CN'));
|
||||
console.log('唐雪 vs 唐波:', '唐雪'.localeCompare('唐波', 'zh-Hans-CN'));
|
||||
Reference in New Issue
Block a user