Skip to content

Instantly share code, notes, and snippets.

@joeeames
Created October 16, 2017 03:12
Show Gist options
  • Save joeeames/10c4c752f3761012e8ce6352ea24d7d3 to your computer and use it in GitHub Desktop.
Save joeeames/10c4c752f3761012e8ce6352ea24d7d3 to your computer and use it in GitHub Desktop.
function isLeapYear(year) {
if(year > 1582 && divisibleBy4(year)) {
if(divisibleBy100ButNot400(year)) {
return false;
} else {
return true;
}
} else {
return false;
}
}
function divisibleBy100ButNot400(year) {
return divisibleBy100(year) && notDivisibleBy400(year)
}
function divisibleBy(year, by) {
return year % by === 0;
}
function divisibleBy4(year) {
return divisibleBy(year, 4);
}
function divisibleBy100(year) {
return divisibleBy(year, 100);
}
function notDivisibleBy400(year) {
return !divisibleBy(year, 400);
}
// function longIf(year) {
// if(year > 1582 && year % 4 === 0 && (year % 100 === 0 && year % 400 !== 0) || {
// }
console.log('2000', isLeapYear(2000) === true)
console.log('2004', isLeapYear(2004) === true)
console.log('2003', isLeapYear(2003) === false)
console.log('1900', isLeapYear(1900) === false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment