Skip to content

Commit 3c636be

Browse files
jveneziano25Josh Veneziano
andauthored
Leap Years: Use more appropriate solution (TheOdinProject#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>
1 parent 435b88b commit 3c636be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const leapYears = function (year) {
2-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
2+
const isYearDivisibleByFour = year % 4 === 0;
3+
const isCentury = year % 100 === 0;
4+
const isYearDivisibleByFourHundred = year % 400 === 0;
5+
6+
if (
7+
isYearDivisibleByFour &&
8+
(!isCentury || isYearDivisibleByFourHundred)
9+
) {
10+
return true;
11+
} else {
12+
return false;
13+
}
314
};
415

516
module.exports = leapYears;

0 commit comments

Comments
 (0)