From e7245ae3f8408a5feeb4f6abe6ad195532c50496 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 20:09:06 -0400 Subject: [PATCH] _.max definitions --- lodash/lodash-tests.ts | 4 +++ lodash/lodash.d.ts | 67 ++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index f786dbc2c..03b7af277 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -300,6 +300,10 @@ result = _.map(stoogesAges, 'name'); result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); result = _.collect(stoogesAges, 'name'); +result = _.max([4, 2, 8, 6]); +result = _.max(stoogesAges, function(stooge) { return stooge.age; }); +result = _.max(stooges, 'age'); + result = _.reduce([1, 2, 3], function(sum, num) { return sum + num; }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 2f2a63e40..11e8cb37f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1342,6 +1342,43 @@ declare module _ { collection: List, pluckValue: string): TResult[]; + /** + * Retrieves the maximum value of a collection. If the collection is empty or falsey -Infinity is + * returned. If a callback is provided it will be executed for each value in the collection to + * generate the criterion by which the value is ranked. The callback is bound to thisArg and invoked + * with three arguments; (value, index, collection). + * + * If a property name is provided for callback the created "_.pluck" style callback will return the + * property value of the given element. + * + * If an object is provided for callback the created "_.where" style callback will return true for + * elements that have the properties of the given object, else false. + * @param collection The collection to iterate over. + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + * @return Returns the maximum value. + **/ + export function max( + collection: Collection, + callback?: ListIterator, + thisArg?: any): T; + + /** + * @see _.max + * @param pluckValue _.pluck style callback + **/ + export function max( + collection: Collection, + pluckValue: string): T; + + /** + * @see _.max + * @param whereValue _.where style callback + **/ + export function max( + collection: Collection, + whereValue: Dictionary): T; + /** * Reduces a collection to a value which is the accumulated result of running each * element in the collection through the callback, where each successive callback execution @@ -1501,16 +1538,6 @@ declare module _ { list: Collection, properties: U): T[]; - /** - * Looks through the list and returns the first value that matches all of the key-value pairs listed in properties. - * @param list Search through this list's elements for the first object with all `properties`. - * @param properties Properties to look for on the elements within `list`. - * @return The first element in `list` that has all `properties`. - **/ - export function findWhere( - list: List, - properties: U): T; - /** * Returns the values in list without the elements that the truth test (iterator) passes. * The opposite of filter. @@ -1542,25 +1569,7 @@ declare module _ { list: Collection, propertyName: string): T[]; - /** - * Returns the maximum value in list. - * @param list Finds the maximum value in this list. - * @return Maximum value in `list`. - **/ - export function max(list: List): number; - - /** - * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate - * the criterion by which the value is ranked. - * @param list Finds the maximum value in this list. - * @param iterator Compares each element in `list` to find the maximum value. - * @param context `this` object in `iterator`, optional. - * @return The maximum element within `list`. - **/ - export function max( - list: Collection, - iterator?: ListIterator, - context?: any): T; + /** * Returns the minimum value in list.