From e59160f94dd27d9754232a4749e79657260db511 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 16:29:27 -0400 Subject: [PATCH] _.countBy definitions and tests --- lodash/lodash-tests.ts | 4 ++++ lodash/lodash.d.ts | 46 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 4ecc5886a..dd2b28d06 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -215,6 +215,10 @@ result = _.contains('curly', 'ur'); result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); result = _.include('curly', 'ur'); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); + result = _.every([true, 1, null, 'yes'], Boolean); result = _.every(stoogesAges, 'age'); result = _.every(stoogesAges, { 'age': 50 }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e0028334b..3d84c0420 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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( + list: Collection, + iterator?: ListIterator, + context?: any): Dictionary; + + /** + * @see _.countBy + * @param iterator Function name + **/ + export function countBy( + list: Collection, + iterator: string, + context?: any): Dictionary; /** * 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; - /** - * 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( - list: Collection, - iterator?: ListIterator, - context?: any): Dictionary; - - /** - * @see _.countBy - * @param iterator Function name - **/ - export function countBy( - list: Collection, - iterator: string, - context?: any): Dictionary; - /** * Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle. * @param list List to shuffle.