Merge pull request #985 from cms/fix-min-max-date
[ENHANCEMENT] Simplify min and max date functions
This commit is contained in:
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
Returns the maximum of the given dates.
|
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.
|
Use the ES6 spread syntax with `Math.max` to find the maximum date value, `new Date()` to convert it to a `Date` object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const maxDate = (...dates) => new Date(Math.max.apply(null, ...dates));
|
const maxDate = dates => new Date(Math.max(...dates));
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
Returns the minimum of the given dates.
|
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.
|
Use the ES6 spread syntax to find the minimum date value, `new Date()` to convert it to a `Date` object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
|
const minDate = dates => new Date(Math.min(...dates));
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const {minDate} = require('./_30s.js');
|
|||||||
test('minDate is a Function', () => {
|
test('minDate is a Function', () => {
|
||||||
expect(minDate).toBeInstanceOf(Function);
|
expect(minDate).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('minDate produces the maximum date', () => {
|
test('minDate produces the minimum date', () => {
|
||||||
const array = [
|
const array = [
|
||||||
new Date(2017, 4, 13),
|
new Date(2017, 4, 13),
|
||||||
new Date(2018, 2, 12),
|
new Date(2018, 2, 12),
|
||||||
|
|||||||
Reference in New Issue
Block a user