Add minDate, maxDate

This commit is contained in:
Angelos Chalaris
2018-09-29 13:38:20 +03:00
parent 82d59bb8de
commit e9c20ed7f5
3 changed files with 40 additions and 0 deletions

19
snippets/maxDate.md Normal file
View File

@ -0,0 +1,19 @@
### maxDate
Returns the maximum of the given dates.
Use `Math.max.apply()` to find the maximum date value, `new Date()` to convert it to a `Date` object.
```js
const maxDate = (...dates) => new Date(Math.max.apply(null, ...dates));
```
```js
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9),
];
maxDate(array); // 2018-03-11T22:00:00.000Z
```

19
snippets/minDate.md Normal file
View File

@ -0,0 +1,19 @@
### minDate
Returns the minimum of the given dates.
Use `Math.min.apply()` to find the minimum date value, `new Date()` to convert it to a `Date` object.
```js
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
```
```js
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9),
];
minDate(array); // 2016-01-08T22:00:00.000Z
```