mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user