Skip to content

Commit

Permalink
Merge pull request #9711 from nallwhy/underscore-find_index
Browse files Browse the repository at this point in the history
[UnderScore] Update definitions of findIndex/findLastIndex
  • Loading branch information
mhegazy committed Jun 21, 2016
2 parents 68f8d5e + 464602f commit f9ff331
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
4 changes: 4 additions & 0 deletions underscore/underscore-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ _.object([['moe', 30], ['larry', 40], ['curly', 50]]);
_.indexOf([1, 2, 3], 2);
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
_.sortedIndex([10, 20, 30, 40, 50], 35);
_.findIndex([1, 2, 3, 1, 2, 3], num => num % 2 === 0);
_.findIndex([{a: 'a'}, {a: 'b'}], {a: 'b'});
_.findLastIndex([1, 2, 3, 1, 2, 3], num => num % 2 === 0);
_.findLastIndex([{ a: 'a' }, { a: 'b' }], { a: 'b' });
_.range(10);
_.range(1, 11);
_.range(0, 30, 5);
Expand Down
27 changes: 6 additions & 21 deletions underscore/underscore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,6 @@ interface UnderscoreStatic {
object: _.List<T>|_.Dictionary<T>,
iterator: string): T;

/**
* Looks through each value in the list, returning the index of the first one that passes a truth
* test (iterator). The function returns as soon as it finds an acceptable element,
* and doesn't traverse the entire list.
* @param list Searches for a value in this list.
* @param iterator Search iterator function for each element in `list`.
* @param context `this` object in `iterator`, optional.
* @return The index of the first acceptable found element in `list`, if nothing is found -1 is returned.
**/
findIndex<T>(
list: _.List<T>,
iterator: _.ListIterator<T, boolean>,
context?: any): number;


/**
* Looks through each value in the list, returning an array of all the values that pass a truth
* test (iterator). Delegates to the native filter method, if it exists.
Expand Down Expand Up @@ -1014,7 +999,7 @@ interface UnderscoreStatic {
**/
findIndex<T>(
array: _.List<T>,
predicate: _.ListIterator<T, boolean>,
predicate: _.ListIterator<T, boolean> | {},
context?: any): number;

/**
Expand All @@ -1026,7 +1011,7 @@ interface UnderscoreStatic {
**/
findLastIndex<T>(
array: _.List<T>,
predicate: _.ListIterator<T, boolean>,
predicate: _.ListIterator<T, boolean> | {},
context?: any): number;

/**
Expand Down Expand Up @@ -4499,12 +4484,12 @@ interface Underscore<T> {
/**
* @see _.findIndex
**/
findIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean>, context?: any): number;
findIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean> | {}, context?: any): number;

/**
* @see _.findLastIndex
**/
findLastIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean>, context?: any): number;
findLastIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean> | {}, context?: any): number;

/**
* Wrapped type `any[]`.
Expand Down Expand Up @@ -5417,12 +5402,12 @@ interface _Chain<T> {
/**
* @see _.findIndex
**/
findIndex<T>(predicate: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
findIndex<T>(predicate: _.ListIterator<T, boolean> | {}, context?: any): _ChainSingle<number>;

/**
* @see _.findLastIndex
**/
findLastIndex<T>(predicate: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
findLastIndex<T>(predicate: _.ListIterator<T, boolean> | {}, context?: any): _ChainSingle<number>;

/**
* Wrapped type `any[]`.
Expand Down

0 comments on commit f9ff331

Please sign in to comment.