2019-03-21 11:52:35 +05:30
|
|
|
---
|
|
|
|
id: 5a23c84252665b21eecc7ede
|
|
|
|
title: Leap year
|
|
|
|
challengeType: 5
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 302300
|
2019-03-21 11:52:35 +05:30
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<section id='description'>
|
2019-07-18 17:32:12 +02:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
Determine whether a given year is a leap year in the Gregorian calendar.
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<section id='instructions'>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<section id='tests'>
|
|
|
|
|
2020-03-30 11:23:18 -05:00
|
|
|
```yml
|
2019-03-21 11:52:35 +05:30
|
|
|
tests:
|
|
|
|
- text: <code>isLeapYear</code> should be a function.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert(typeof isLeapYear == 'function');
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear()</code> should return a boolean.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert(typeof isLeapYear(2018) == 'boolean');
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(2018)</code> should return <code>false</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(2018), false);
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(2016)</code> should return <code>true</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(2016), true);
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(2000)</code> should return <code>true</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(2000), true);
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(1900)</code> should return <code>false</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(1900), false);
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(1996)</code> should return <code>true</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(1996), true);
|
2019-03-21 11:52:35 +05:30
|
|
|
- text: <code>isLeapYear(1800)</code> should return <code>false</code>.
|
2020-03-30 11:23:18 -05:00
|
|
|
testString: assert.equal(isLeapYear(1800), false);
|
2019-03-21 11:52:35 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<section id='challengeSeed'>
|
2019-07-18 17:32:12 +02:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function isLeapYear(year) {
|
2020-09-15 09:57:40 -07:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2019-03-21 11:52:35 +05:30
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
2020-03-30 11:23:18 -05:00
|
|
|
function isLeapYear(year) {
|
|
|
|
return year % 100 === 0 ? year % 400 === 0 : year % 4 === 0;
|
|
|
|
}
|
2019-03-21 11:52:35 +05:30
|
|
|
```
|
|
|
|
|
2019-07-18 17:32:12 +02:00
|
|
|
</section>
|