Skip to content

Instantly share code, notes, and snippets.

@khoazero123
Created August 13, 2020 01:49
Show Gist options
  • Select an option

  • Save khoazero123/34cd48149eca1a17d7967a75fdedf6d3 to your computer and use it in GitHub Desktop.

Select an option

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.
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