diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 13a35e409..f65eebdff 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -142,6 +142,18 @@ result = _.remove([1, 2, 3, 4, 5, 6], function(num) { return num % 2 = result = _.remove(foodsOrganic, 'organic'); result = _.remove(foodsType, { 'type': 'vegetable'}); +result = _.sortedIndex([20, 30, 50], 40); +result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); +var sortedIndexDict = { + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } +}; +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return sortedIndexDict.wordToNumber[word]; +}); +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return this.wordToNumber[word]; +}, sortedIndexDict); + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 020e56fe1..215d22483 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -509,6 +509,46 @@ declare module _ { wherealue?: Dictionary): any[]; + /** + * Uses a binary search to determine the smallest index at which a value should be inserted + * into a given sorted array in order to maintain the sort order of the array. If a callback + * is provided it will be executed for value and each element of array to compute their sort + * ranking. The callback is bound to thisArg and invoked with one argument; (value). + * + * 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 list The sorted list. + * @param value The value to determine its index within `list`. + * @param iterator Iterator to compute the sort ranking of each value, optional. + * @return The index at which value should be inserted into array. + **/ + export function sortedIndex( + array: List, + value: T, + callback?: (x: T) => TSort, + thisArg?: any): number; + + /** + * @see _.sortedIndex + * @param pluckValue the _.pluck style callback + **/ + export function sortedIndex( + array: List, + value: T, + pluckValue: string): number; + + /** + * @see _.sortedIndex + * @param pluckValue the _.where style callback + **/ + export function sortedIndex( + array: List, + value: T, + whereValue: Dictionary): number; + /* ************* * Collections * ************* */ @@ -1182,19 +1222,7 @@ declare module _ { - /** - * Uses a binary search to determine the index at which the value should be inserted into the list in order - * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking - * of each value, including the value you pass. - * @param list The sorted list. - * @param value The value to determine its index within `list`. - * @param iterator Iterator to compute the sort ranking of each value, optional. - * @return The index where `value` should be inserted into `list`. - **/ - export function sortedIndex( - list: List, - value: T, - iterator?: (x: T) => TSort, context?: any): number; +