From 3c636bebeee1259f7247881c5749e59df0524712 Mon Sep 17 00:00:00 2001 From: jveneziano25 <75101927+jveneziano25@users.noreply.github.com> Date: Thu, 27 Jun 2024 06:25:01 -0500 Subject: [PATCH] Leap Years: Use more appropriate solution (#483) Replacement solution is closer to what most learners might think of due to the instructions' hints, and concepts they'll have been reasonably exposed to so far in the curriculum. The original solution has been a curveball for quite a few people. Co-authored-by: Josh Veneziano --- 06_leapYears/solution/leapYears-solution.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/06_leapYears/solution/leapYears-solution.js b/06_leapYears/solution/leapYears-solution.js index 588bfd7..cd1f5c7 100644 --- a/06_leapYears/solution/leapYears-solution.js +++ b/06_leapYears/solution/leapYears-solution.js @@ -1,5 +1,16 @@ const leapYears = function (year) { - return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); + const isYearDivisibleByFour = year % 4 === 0; + const isCentury = year % 100 === 0; + const isYearDivisibleByFourHundred = year % 400 === 0; + + if ( + isYearDivisibleByFour && + (!isCentury || isYearDivisibleByFourHundred) + ) { + return true; + } else { + return false; + } }; module.exports = leapYears;