Merge pull request #6102 from chrootsu/lodash-findLastIndex

lodash: changed _.findLastIndex() method
This commit is contained in:
Masahiro Wakame
2015-10-05 22:31:47 +09:00
2 changed files with 114 additions and 43 deletions
+35 -5
View File
@@ -297,11 +297,41 @@ module TestFindIndex {
result = _(list).findIndex<{a: number}>({a: 42});
}
result = <number>_.findLastIndex(['apple', 'banana', 'beet'], function (f: string) {
return /^b/.test(f);
});
result = <number>_.findLastIndex(['apple', 'banana', 'beet'], 'apple');
result = <number>_.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' });
// _.findLastIndex
module TestFindLastIndex {
let array: TResult[];
let list: _.List<TResult>;
let predicateFn: (value: TResult, index?: number, collection?: _.List<TResult>) => boolean;
let result: number;
result = _.findLastIndex<TResult>(array);
result = _.findLastIndex<TResult>(array, predicateFn);
result = _.findLastIndex<TResult>(array, predicateFn, any);
result = _.findLastIndex<TResult>(array, '');
result = _.findLastIndex<TResult>(array, '', any);
result = _.findLastIndex<{a: number}, TResult>(array, {a: 42});
result = _.findLastIndex<TResult>(list);
result = _.findLastIndex<TResult>(list, predicateFn);
result = _.findLastIndex<TResult>(list, predicateFn, any);
result = _.findLastIndex<TResult>(list, '');
result = _.findLastIndex<TResult>(list, '', any);
result = _.findLastIndex<{a: number}, TResult>(list, {a: 42});
result = _<TResult>(array).findLastIndex();
result = _<TResult>(array).findLastIndex(predicateFn);
result = _<TResult>(array).findLastIndex(predicateFn, any);
result = _<TResult>(array).findLastIndex('');
result = _<TResult>(array).findLastIndex('', any);
result = _<TResult>(array).findLastIndex<{a: number}>({a: 42});
result = _(list).findLastIndex();
result = _(list).findLastIndex<TResult>(predicateFn);
result = _(list).findLastIndex<TResult>(predicateFn, any);
result = _(list).findLastIndex('');
result = _(list).findLastIndex('', any);
result = _(list).findLastIndex<{a: number}>({a: 42});
}
// _.first
module TestFirst {
+79 -38
View File
@@ -554,53 +554,94 @@ declare module _ {
//_.findLastIndex
interface LoDashStatic {
/**
* This method is like _.findIndex except that it iterates over elements of a collection from right to left.
* @param array The array to search.
* @param {(Function|Object|string)} callback The function called per iteration. If a property name or object is provided it will be
* used to create a ".pluck" or ".where" style callback, respectively.
* @param thisArg The this binding of callback.
* @return Returns the index of the found element, else -1.
**/
findLastIndex<T>(
array: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): number;
/**
* @see _.findLastIndex
**/
* This method is like _.findIndex except that it iterates over elements of collection from right to left.
*
* If a property name is provided for predicate the created _.property style callback returns the property
* value of the given element.
*
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
* elements that have a matching property value, else false.
*
* If an object is provided for predicate the created _.matches style callback returns true for elements that
* have the properties of the given object, else false.
*
* @param array The array to search.
* @param predicate The function invoked per iteration.
* @param thisArg The function invoked per iteration.
* @return Returns the index of the found element, else -1.
*/
findLastIndex<T>(
array: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): number;
predicate?: ListIterator<T, boolean>,
thisArg?: any
): number;
/**
* @see _.findLastIndex
**/
findLastIndex<T>(
array: Array<T>,
pluckValue: string): number;
/**
* @see _.findLastIndex
**/
* @see _.findLastIndex
*/
findLastIndex<T>(
array: List<T>,
pluckValue: string): number;
predicate?: string,
thisArg?: any
): number;
/**
* @see _.findLastIndex
**/
findLastIndex<T>(
array: Array<T>,
whereDictionary: Dictionary<any>): number;
/**
* @see _.findLastIndex
**/
findLastIndex<T>(
* @see _.findLastIndex
*/
findLastIndex<W, T>(
array: List<T>,
whereDictionary: Dictionary<any>): number;
predicate?: W
): number;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.findLastIndex
*/
findLastIndex(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): number;
/**
* @see _.findLastIndex
*/
findLastIndex(
predicate?: string,
thisArg?: any
): number;
/**
* @see _.findLastIndex
*/
findLastIndex<W>(
predicate?: W
): number;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.findLastIndex
*/
findLastIndex<TResult>(
predicate?: ListIterator<TResult, boolean>,
thisArg?: any
): number;
/**
* @see _.findLastIndex
*/
findLastIndex(
predicate?: string,
thisArg?: any
): number;
/**
* @see _.findLastIndex
*/
findLastIndex<W>(
predicate?: W
): number;
}
//_.first