lodash: added _.sortedLastIndex

This commit is contained in:
Bram Pouwelse
2015-10-29 12:02:42 +01:00
parent 48fb3e197a
commit 48426c6590
2 changed files with 85 additions and 0 deletions
+15
View File
@@ -714,6 +714,21 @@ module TestSortedIndex {
}, sortedIndexDict);
}
// _.sortedLastIndex
module TestSortedLastIndex {
result = <number>_.sortedLastIndex([20, 30, 50], 40);
result = <number>_.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 = <number>_.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return sortedLastIndexDict.wordToNumber[word];
});
result = <number>_.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return this.wordToNumber[word];
}, sortedLastIndexDict);
}
// _.tail
module TestTail {
let array: TResult[];
+70
View File
@@ -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<T, TSort>(
array: Array<T>,
value: T,
callback?: (x: T) => TSort,
thisArg?: any): number;
/**
* @see _.sortedLastIndex
**/
sortedLastIndex<T, TSort>(
array: List<T>,
value: T,
callback?: (x: T) => TSort,
thisArg?: any): number;
/**
* @see _.sortedLastIndex
* @param pluckValue the _.pluck style callback
**/
sortedLastIndex<T>(
array: Array<T>,
value: T,
pluckValue: string): number;
/**
* @see _.sortedLastIndex
* @param pluckValue the _.pluck style callback
**/
sortedLastIndex<T>(
array: List<T>,
value: T,
pluckValue: string): number;
/**
* @see _.sortedLastIndex
* @param pluckValue the _.where style callback
**/
sortedLastIndex<W, T>(
array: Array<T>,
value: T,
whereValue: W): number;
/**
* @see _.sortedLastIndex
* @param pluckValue the _.where style callback
**/
sortedLastIndex<W, T>(
array: List<T>,
value: T,
whereValue: W): number;
}
//_.tail
interface LoDashStatic {
/**