Created
October 8, 2015 11:32
-
-
Save manjeettahkur/1ad26b2aab12b2c3e7c8 to your computer and use it in GitHub Desktop.
In this kata you should simply determine, whether a given year is a leap year or not
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
Description: | |
In this kata you should simply determine, whether a given year is a leap year or not. In case you don't know the rules, here they are: | |
years divisible by 4 are leap years | |
but years divisible by 100 are no leap years | |
but years divisible by 400 are leap years | |
Additional Notes: | |
Only valid years (positive integers) will be tested, so you don't have to validate them | |
Examples can be found in the test fixture. | |
Solution 1. | |
function isLeapYear(year) { | |
return (year % 100 !== 0 && year % 4 === 0) || year % 400 === 0; | |
} | |
Solution 2. | |
function isLeapYear(year) { | |
return (year / 4) % 4 === 0; | |
} | |
Solution 3. | |
function isLeapYear(year) { | |
function isDiv(num){ | |
return year/num === parseInt(year/num) | |
} | |
return isDiv(4) && !isDiv(100) || isDiv(400) | |
} | |
Solution 4. | |
function isLeapYear(year) { | |
if(0 == year%400) return true; | |
if(0 == year%100) return false; | |
if(0 == year%4) return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment