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 <jveneziano@proton.me>
This commit is contained in:
jveneziano25
2024-06-27 06:25:01 -05:00
committed by GitHub
parent 435b88bf19
commit 3c636bebee
+12 -1
View File
@@ -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;