Create a function that determines whether or not a given year is a leap year. Leap years are determined by the following rules

This commit is contained in:
Akutsang 2023-02-03 15:01:26 +01:00
parent fe6db15bb3
commit 4204350a10
2 changed files with 15 additions and 6 deletions

View File

@ -1,4 +1,13 @@
const leapYears = function() {
const leapYears = function(input) {
if (input % 4 != 0) {
return false;
}
if(input % 4 == 0 && input % 400 == 0 || input % 100 != 0){
return true
}
if (input % 100 == 0 && input % 400 != 0) {
return false;
}
};

View File

@ -4,19 +4,19 @@ describe('leapYears', () => {
test('works with non century years', () => {
expect(leapYears(1996)).toBe(true);
});
test.skip('works with non century years', () => {
test('works with non century years', () => {
expect(leapYears(1997)).toBe(false);
});
test.skip('works with ridiculously futuristic non century years', () => {
test('works with ridiculously futuristic non century years', () => {
expect(leapYears(34992)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1900)).toBe(false);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1600)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(700)).toBe(false);
});
});