This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ import swapElements from './swapElements'
6060import reverse from './reverse'
6161import removeAccents from './remove-accents'
6262import getQueryStringValue from './get-query-string-value'
63+ import isLeapYear from './leap-year'
6364
6465export {
6566 reverseArrayInPlace ,
@@ -124,4 +125,5 @@ export {
124125 removeAccents ,
125126 getQueryStringValue ,
126127 lessThan ,
128+ isLeapYear ,
127129}
Original file line number Diff line number Diff line change 1+ export default isLeapYear
2+
3+ /**
4+ * This method will check if the given year is a leap year.
5+ * More information on http://www.youtube.com/watch?v=xX96xng7sAE
6+ *
7+ * @param {Number } year - year to check if leap year
8+ * @return {Bool } - Resul if year is leap year
9+ */
10+ function isLeapYear ( year ) {
11+ return year % 4 === 0 && ( year % 100 !== 0 || year % 400 === 0 )
12+ }
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+ import leapYear from '../src/leap-year'
3+
4+ test ( 'leap year is every 4 years to adjust about a day' , t => {
5+ const year = 2016
6+ const expected = true
7+ const actual = leapYear ( year )
8+ t . deepEqual ( actual , expected )
9+ } )
10+
11+ test ( 'Leap year is skipped every 100 years to remove an extra day' , t => {
12+ const year = 1900
13+ const expected = false
14+ const actual = leapYear ( year )
15+ t . deepEqual ( actual , expected )
16+ } )
17+
18+ test ( 'Leap year is reintroduced every 400 years to adjust another day' , t => {
19+ const year = 2000
20+ const expected = true
21+ const actual = leapYear ( year )
22+ t . deepEqual ( actual , expected )
23+ } )
24+
25+ test ( 'A year that is not a leap year' , t => {
26+ const year = 1978
27+ const expected = false
28+ const actual = leapYear ( year )
29+ t . deepEqual ( actual , expected )
30+ } )
You can’t perform that action at this time.
0 commit comments