From 50c2e67f1267d68222d06377f850d1ee852f513d Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 21:07:42 -0400 Subject: [PATCH] _.sortBy definitions --- lodash/lodash-tests.ts | 6 +++++ lodash/lodash.d.ts | 58 +++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 064ca9904..5dba02cba 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -359,6 +359,12 @@ result = _.some(foodsCombined, { 'type': 'meat' }); result = _.any(foodsCombined, 'organic'); result = _.any(foodsCombined, { 'type': 'meat' }); +result = _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); +result = _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); +result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); + + + diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 1da7ff799..17886cd77 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1624,6 +1624,42 @@ declare module _ { collection: Collection, whereValue: Dictionary): boolean; + /** + * Creates an array of elements, sorted in ascending order by the results of running each + * element in a collection through the callback. This method performs a stable sort, that + * is, it will preserve the original sort order of equal elements. The callback is bound + * to thisArg and invoked with three arguments; (value, index|key, 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 A new array of sorted elements. + **/ + export function sortBy( + collection: List, + callback?: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.sortBy + * @param pluckValue _.pluck style callback + **/ + export function sortBy( + collection: List, + pluckValue: string): T[]; + + /** + * @see _.sortBy + * @param whereValue _.where style callback + **/ + export function sortBy( + collection: List, + whereValue: Dictionary): T[]; @@ -1663,27 +1699,7 @@ declare module _ { list: Collection, properties: U): T[]; - /** - * Returns a sorted copy of list, ranked in ascending order by the results of running each value - * through iterator. Iterator may also be the string name of the property to sort by (eg. length). - * @param list Sorts this list. - * @param iterator Sort iterator for each element within `list`. - * @param context `this` object in `iterator`, optional. - * @return A sorted copy of `list`. - **/ - export function sortBy( - list: List, - iterator?: ListIterator, - context?: any): T[]; - - /** - * @see _.sortBy - * @param iterator Sort iterator for each element within `list`. - **/ - export function sortBy( - list: List, - iterator: string, - context?: any): T[]; +