Merge pull request #6515 from brampouwelse/master

lodash: added _.sortedLastIndex
This commit is contained in:
Masahiro Wakame
2015-11-02 23:42:00 +09:00
2 changed files with 99 additions and 11 deletions
+29 -11
View File
@@ -942,17 +942,35 @@ module TestSlice {
}
}
result = <number>_.sortedIndex([20, 30, 50], 40);
result = <number>_.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 = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return sortedIndexDict.wordToNumber[word];
});
result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return this.wordToNumber[word];
}, sortedIndexDict);
// _.sortedIndex
module TestSortedIndex {
result = <number>_.sortedIndex([20, 30, 50], 40);
result = <number>_.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 = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return sortedIndexDict.wordToNumber[word];
});
result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return this.wordToNumber[word];
}, 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 {
+70
View File
@@ -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<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 {
/**