_.countBy definitions and tests

This commit is contained in:
Brian Zengel
2013-10-18 16:29:27 -04:00
parent 4eeaabe3d9
commit e59160f94d
2 changed files with 27 additions and 23 deletions
+4
View File
@@ -215,6 +215,10 @@ result = <boolean>_.contains('curly', 'ur');
result = <boolean>_.include({ 'name': 'moe', 'age': 40 }, 'moe');
result = <boolean>_.include('curly', 'ur');
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); });
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
result = <_.Dictionary<number>>_.countBy(['one', 'two', 'three'], 'length');
result = <boolean>_.every([true, 1, null, 'yes'], Boolean);
result = <boolean>_.every(stoogesAges, 'age');
result = <boolean>_.every(stoogesAges, { 'age': 50 });
+23 -23
View File
@@ -841,6 +841,29 @@ declare module _ {
searchString: string,
targetString: string,
fromIndex?: number): boolean;
/**
* Sorts a list into groups and returns a count for the number of objects in each group. Similar
* to groupBy, but instead of returning a list of values, returns a count for the number of values
* in that group.
* @param list Group elements in this list and then count the number of elements in each group.
* @param iterator Group iterator for each element within `list`, return the key to group the element by.
* @param context `this` object in `iterator`, optional.
* @return An object with the group names as properties where each property contains the number of elements in that group.
**/
export function countBy<T>(
list: Collection<T>,
iterator?: ListIterator<T, any>,
context?: any): Dictionary<number>;
/**
* @see _.countBy
* @param iterator Function name
**/
export function countBy<T>(
list: Collection<T>,
iterator: string,
context?: any): Dictionary<number>;
/**
* Checks if the given callback returns truey value for all elements of a collection.
@@ -1360,29 +1383,6 @@ declare module _ {
iterator: string,
context?: any): Dictionary<T>;
/**
* Sorts a list into groups and returns a count for the number of objects in each group. Similar
* to groupBy, but instead of returning a list of values, returns a count for the number of values
* in that group.
* @param list Group elements in this list and then count the number of elements in each group.
* @param iterator Group iterator for each element within `list`, return the key to group the element by.
* @param context `this` object in `iterator`, optional.
* @return An object with the group names as properties where each property contains the number of elements in that group.
**/
export function countBy<T>(
list: Collection<T>,
iterator?: ListIterator<T, any>,
context?: any): Dictionary<number[]>;
/**
* @see _.countBy
* @param iterator Function name
**/
export function countBy<T>(
list: Collection<T>,
iterator: string,
context?: any): Dictionary<number[]>;
/**
* Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle.
* @param list List to shuffle.