Skip to content

Instantly share code, notes, and snippets.

@hansputera
Created February 20, 2023 09:49
Show Gist options
  • Save hansputera/4d6eae22567f729bc2113288237a99d1 to your computer and use it in GitHub Desktop.
Save hansputera/4d6eae22567f729bc2113288237a99d1 to your computer and use it in GitHub Desktop.
Sort Indonesia Day Names
function sortIndonesiaDays(days: string[]): string[] {
return days.sort((a, b) => {
a = a.toLowerCase();
b = b.toLowerCase();
if (a === 'sabtu' || b === 'sabtu') {
return a === 'sabtu' ? 1 : -1;
} else if (a < b) {
return 1;
}
return 0;
});
}
const days = [
'Selasa',
'Rabu',
'Kamis',
'Sabtu',
'Jumat',
'Kamis',
'Kemis',
'Senin',
'Jumat'
];
const sortedDays = sortIndonesiaDays(days);
console.log(sortedDays);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment