diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2c42fd269..e9366aa6e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -942,17 +942,35 @@ module TestSlice { } } -result = _.sortedIndex([20, 30, 50], 40); -result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); -var sortedIndexDict: { wordToNumber: { [idx: string]: number } } = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } -}; -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return sortedIndexDict.wordToNumber[word]; -}); -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return this.wordToNumber[word]; -}, sortedIndexDict); +// _.sortedIndex +module TestSortedIndex { + result = _.sortedIndex([20, 30, 50], 40); + result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); + var sortedIndexDict: { wordToNumber: { [idx: string]: number } } = { + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } + }; + result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { + return sortedIndexDict.wordToNumber[word]; + }); + result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { + return this.wordToNumber[word]; + }, 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 { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index cccf88078..4575749f6 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1679,6 +1679,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 { /**