diff --git a/snippets/maxDate.md b/snippets/maxDate.md new file mode 100644 index 000000000..bf2677476 --- /dev/null +++ b/snippets/maxDate.md @@ -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 +``` diff --git a/snippets/minDate.md b/snippets/minDate.md new file mode 100644 index 000000000..2a0c35456 --- /dev/null +++ b/snippets/minDate.md @@ -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 +``` diff --git a/tag_database b/tag_database index 52a817d0a..6693e7bd9 100644 --- a/tag_database +++ b/tag_database @@ -173,11 +173,13 @@ mask:string,utility,regexp,intermediate matches:object,type,intermediate matchesWith:object,type,function,intermediate maxBy:math,array,function,beginner +maxDate:date,math,beginner maxN:array,math,beginner median:math,array,intermediate memoize:function,advanced merge:object,array,intermediate minBy:math,array,function,beginner +minDate:date,math,beginner minN:array,math,beginner mostPerformant:utility,function negate:function,beginner