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
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: leap-year
|
2019-03-21 11:52:35 +05:30
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --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
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear` should be a function.
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(typeof isLeapYear == 'function');
|
|
|
|
```
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear()` should return a boolean.
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(typeof isLeapYear(2018) == 'boolean');
|
|
|
|
```
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(2018)` should return `false`.
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.equal(isLeapYear(2018), false);
|
2019-03-21 11:52:35 +05:30
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(2016)` should return `true`.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(isLeapYear(2016), true);
|
|
|
|
```
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(2000)` should return `true`.
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.equal(isLeapYear(2000), true);
|
|
|
|
```
|
2019-07-18 17:32:12 +02:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(1900)` should return `false`.
|
2019-03-21 11:52:35 +05:30
|
|
|
|
|
|
|
```js
|
2020-11-27 19:02:05 +01:00
|
|
|
assert.equal(isLeapYear(1900), false);
|
|
|
|
```
|
2020-09-15 09:57:40 -07:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(1996)` should return `true`.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(isLeapYear(1996), true);
|
2019-03-21 11:52:35 +05:30
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`isLeapYear(1800)` should return `false`.
|
2019-03-21 11:52:35 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.equal(isLeapYear(1800), false);
|
|
|
|
```
|
2020-03-30 11:23:18 -05:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
2019-03-21 11:52:35 +05:30
|
|
|
|
|
|
|
```js
|
2020-03-30 11:23:18 -05:00
|
|
|
function isLeapYear(year) {
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2020-03-30 11:23:18 -05:00
|
|
|
}
|
2019-03-21 11:52:35 +05:30
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function isLeapYear(year) {
|
|
|
|
return year % 100 === 0 ? year % 400 === 0 : year % 4 === 0;
|
|
|
|
}
|
|
|
|
```
|