diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9b1698871..7bc8c6568 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -714,6 +714,21 @@ module TestSortedIndex { }, sortedIndexDict); } +// _.sortedLastIndex +module TestSortedLastIndex { + result = _.sortedLastIndex([20, 30, 50], 40); + result = _.sortedLastIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); + var sortedLastIndexDict: { wordToNumber: { [idx: string]: number } } = { + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } + }; + result = _.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { + return sortedLastIndexDict.wordToNumber[word]; + }); + result = _.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { + return this.wordToNumber[word]; + }, sortedLastIndexDict); +} + // _.tail module TestTail { let array: TResult[]; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index d143f4e65..369b9a926 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1409,6 +1409,76 @@ declare module _ { whereValue: W): number; } + //_.sortedLastIndex + interface LoDashStatic { + /** + * Uses a binary search to determine the highest 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 array The sorted list. + * @param value The value to determine its index within `list`. + * @param callback Iterator to compute the sort ranking of each value, optional. + * @return The index at which value should be inserted into array. + **/ + sortedLastIndex( + array: Array, + value: T, + callback?: (x: T) => TSort, + thisArg?: any): number; + + /** + * @see _.sortedLastIndex + **/ + sortedLastIndex( + array: List, + value: T, + callback?: (x: T) => TSort, + thisArg?: any): number; + + /** + * @see _.sortedLastIndex + * @param pluckValue the _.pluck style callback + **/ + sortedLastIndex( + array: Array, + value: T, + pluckValue: string): number; + + /** + * @see _.sortedLastIndex + * @param pluckValue the _.pluck style callback + **/ + sortedLastIndex( + array: List, + value: T, + pluckValue: string): number; + + /** + * @see _.sortedLastIndex + * @param pluckValue the _.where style callback + **/ + sortedLastIndex( + array: Array, + value: T, + whereValue: W): number; + + /** + * @see _.sortedLastIndex + * @param pluckValue the _.where style callback + **/ + sortedLastIndex( + array: List, + value: T, + whereValue: W): number; + } + //_.tail interface LoDashStatic { /**