File tree Expand file tree Collapse file tree 4 files changed +46
-1
lines changed
Expand file tree Collapse file tree 4 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 156156 * [ IsDivisible] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/IsDivisible.js )
157157 * [ IsEven] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/IsEven.js )
158158 * [ isOdd] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/isOdd.js )
159+ * [ LeapYear] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/LeapYear.js )
159160 * [ Mandelbrot] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Mandelbrot.js )
160161 * [ MatrixExponentiationRecursive] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/MatrixExponentiationRecursive.js )
161162 * [ MatrixMultiplication] ( https://github.com/TheAlgorithms/Javascript/blob/master/Maths/MatrixMultiplication.js )
Original file line number Diff line number Diff line change 1+ /**
2+ * isLeapYear :: Number -> Boolean
3+ *
4+ * Check if a year is a leap year or not. A leap year is a year which has 366 days.
5+ * For the extra +1 day the February month contains 29 days instead of 28 days.
6+ *
7+ * The logic behind the leap year is-
8+ * 1. If the year is divisible by 400 then it is a leap year.
9+ * 2. If it is not divisible by 400 but divisible by 100 then it is not a leap year.
10+ * 3. If the year is not divisible by 400 but not divisible by 100 and divisible by 4 then a leap year.
11+ * 4. Other cases except the describing ones are not a leap year.
12+ *
13+ * @param {number } year
14+ * @returns {boolean } true if this is a leap year, false otherwise.
15+ */
16+ export const isLeapYear = ( year ) => {
17+ if ( year % 400 === 0 ) return true
18+ if ( year % 100 === 0 ) return false
19+ if ( year % 4 === 0 ) return true
20+
21+ return false
22+ }
Original file line number Diff line number Diff line change 1+ import { isLeapYear } from '../LeapYear'
2+
3+ describe ( 'Leap Year' , ( ) => {
4+ it ( 'Should return true on the year 2000' , ( ) => {
5+ expect ( isLeapYear ( 2000 ) ) . toBe ( true )
6+ } )
7+ it ( 'Should return false on the year 2001' , ( ) => {
8+ expect ( isLeapYear ( 2001 ) ) . toBe ( false )
9+ } )
10+ it ( 'Should return false on the year 2002' , ( ) => {
11+ expect ( isLeapYear ( 2002 ) ) . toBe ( false )
12+ } )
13+ it ( 'Should return false on the year 2003' , ( ) => {
14+ expect ( isLeapYear ( 2003 ) ) . toBe ( false )
15+ } )
16+ it ( 'Should return false on the year 2004' , ( ) => {
17+ expect ( isLeapYear ( 2004 ) ) . toBe ( true )
18+ } )
19+ it ( 'Should return false on the year 1900' , ( ) => {
20+ expect ( isLeapYear ( 1900 ) ) . toBe ( false )
21+ } )
22+ } )
Original file line number Diff line number Diff line change 3131 "jest" : " ^26.4.2" ,
3232 "standard" : " ^14.3.4"
3333 }
34- }
34+ }
You can’t perform that action at this time.
0 commit comments