_.max definitions

This commit is contained in:
Brian Zengel
2013-10-18 20:09:06 -04:00
parent 750bc30375
commit e7245ae3f8
2 changed files with 42 additions and 29 deletions
+4
View File
@@ -300,6 +300,10 @@ result = <any[]>_.map(stoogesAges, 'name');
result = <any[]>_.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });
result = <any[]>_.collect(stoogesAges, 'name');
result = <number>_.max([4, 2, 8, 6]);
result = <IStoogesAge>_.max(stoogesAges, function(stooge) { return stooge.age; });
result = <IStoogesAge>_.max(stooges, 'age');
result = <any>_.reduce([1, 2, 3], function(sum, num) {
return sum + num;
});
+38 -29
View File
@@ -1342,6 +1342,43 @@ declare module _ {
collection: List<T>,
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<T>(
collection: Collection<T>,
callback?: ListIterator<T, any>,
thisArg?: any): T;
/**
* @see _.max
* @param pluckValue _.pluck style callback
**/
export function max<T>(
collection: Collection<T>,
pluckValue: string): T;
/**
* @see _.max
* @param whereValue _.where style callback
**/
export function max<T>(
collection: Collection<T>,
whereValue: Dictionary<any>): 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<T>,
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<T, U extends {}>(
list: List<T>,
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<T>,
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>): 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<T>(
list: Collection<T>,
iterator?: ListIterator<T, any>,
context?: any): T;
/**
* Returns the minimum value in list.