Created
February 20, 2023 09:49
-
-
Save hansputera/4d6eae22567f729bc2113288237a99d1 to your computer and use it in GitHub Desktop.
Sort Indonesia Day Names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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