Created
October 16, 2017 03:12
-
-
Save joeeames/10c4c752f3761012e8ce6352ea24d7d3 to your computer and use it in GitHub Desktop.
This file contains 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) { | |
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