E5D8 also tried the boolean expression solution · unconnect/javascript-exercises@5bc4b4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bc4b4b

Browse files
committed
also tried the boolean expression solution
1 parent bdf22c8 commit 5bc4b4b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

06_leapYears/leapYears.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
const leapYears = function(givenYear) {
2+
3+
// Solution with ifs
4+
25
// years divisible by 4 are no leap years
3-
if(givenYear % 4 !== 0) return false;
6+
// if(givenYear % 4 !== 0) return false;
47
// century years are no leap years, unless divisible by 400
5-
if(givenYear % 100 === 0 && givenYear % 400 !== 0) return false;
6-
return true;
8+
// if(givenYear % 100 === 0 && givenYear % 400 !== 0) return false;
9+
// return true;
10+
11+
// very elegantly solution with boolean expression
12+
return givenYear % 4 === 0 && (givenYear % 100 !== 0 || givenYear % 400 === 0);
13+
714
};
815

916
// Do not edit below this line

0 commit comments

Comments
 (0)
0