add isLeapYear snippet

This commit is contained in:
Afif
2020-02-05 19:00:03 +07:00
committed by Angelos Chalaris
parent 330b2a0766
commit a7642fa103

19
snippets/isLeapYear.md Normal file
View File

@ -0,0 +1,19 @@
---
title: isLeapYear
tags: function,date,beginner
---
Returns `true` if year is leap year.
Use `new Date()`, set the date to 29st february `year`, check if the month is equal with 1 then return `true`
```js
const isLeapYear = (year) => {
return new Date(year, 1, 29).getMonth() === 1
}
```
```js
isLeapYear(2019); // false
isLeapYear(2020); // true
```