Created
August 13, 2020 01:49
-
-
Save khoazero123/34cd48149eca1a17d7967a75fdedf6d3 to your computer and use it in GitHub Desktop.
Your task is to write a function that determines whether a year entered in traditional Japanese format is a leap year or not.
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 isLeapYear(year) { | |
| let yearInEra; | |
| let [_, firstLetter, numOfYear] = /(\w)(\d+)/.exec(year); | |
| numOfYear = parseInt(numOfYear) - 1; | |
| switch (firstLetter) { | |
| case 'M': | |
| yearInEra = 1868 + numOfYear; | |
| break; | |
| case 'T': | |
| yearInEra = 1912 + numOfYear; | |
| break; | |
| case 'S': | |
| yearInEra = 1926 + numOfYear; | |
| break; | |
| case 'H': | |
| yearInEra = 1989 + numOfYear; | |
| break; | |
| case 'R': | |
| yearInEra = 2019 + numOfYear; | |
| break; | |
| } | |
| if (yearInEra % 4 === 0) { | |
| if ( yearInEra % 100 === 0 ) { | |
| return yearInEra % 400 === 0 ? 1 : 0; | |
| } | |
| return 1; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment