From 4204350a10e89b71a33b304913d4550c1b44fb82 Mon Sep 17 00:00:00 2001 From: Akutsang Date: Fri, 3 Feb 2023 15:01:26 +0100 Subject: [PATCH] Create a function that determines whether or not a given year is a leap year. Leap years are determined by the following rules --- 06_leapYears/leapYears.js | 11 ++++++++++- 06_leapYears/leapYears.spec.js | 10 +++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/06_leapYears/leapYears.js b/06_leapYears/leapYears.js index 681eeef..aec4afe 100644 --- a/06_leapYears/leapYears.js +++ b/06_leapYears/leapYears.js @@ -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; +} }; diff --git a/06_leapYears/leapYears.spec.js b/06_leapYears/leapYears.spec.js index 6fdaba9..2cd4110 100644 --- a/06_leapYears/leapYears.spec.js +++ b/06_leapYears/leapYears.spec.js @@ -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); }); });