mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
definitions for _.indexOf
This commit is contained in:
+17
-7
@@ -12,6 +12,10 @@ interface IFoodType {
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface IStoogesQuotes {
|
||||
name: string;
|
||||
quotes: string[];
|
||||
}
|
||||
|
||||
var foodsOrganic: IFoodOrganic[] = [
|
||||
{ name: 'banana', organic: true },
|
||||
@@ -22,8 +26,13 @@ var foodsType: IFoodType[] = [
|
||||
{ name: 'banana', type: 'fruit' },
|
||||
{ name: 'beet', type: 'vegetable' }
|
||||
];
|
||||
var stoogesQuotes = [
|
||||
{ 'name': 'curly', 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] },
|
||||
{ 'name': 'moe', 'quotes': ['Spread out!', 'You knucklehead!'] }
|
||||
];
|
||||
var result;
|
||||
|
||||
//Array Method Tests
|
||||
result = <any[]>_.compact([0, 1, false, 2, '', 3]);
|
||||
result = <number[]>_.difference([1, 2, 3, 4, 5], [5, 2, 10]);
|
||||
|
||||
@@ -88,6 +97,13 @@ result = <number[]>_.take([1, 2, 3], function(num) {
|
||||
result = <IFoodOrganic[]>_.take(foodsOrganic, 'organic');
|
||||
result = <IFoodType[]>_.take(foodsType, { 'type': 'fruit' });
|
||||
|
||||
result = <number[]>_.flatten([1, [2], [3, [[4]]]]);
|
||||
result = <any[]>_.flatten([1, [2], [3, [[4]]]], true);
|
||||
result = <string[]>_.flatten(stoogesQuotes, 'quotes');
|
||||
|
||||
result = <number>_.indexOf([1, 2, 3, 1, 2, 3], 2);
|
||||
result = <number>_.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
|
||||
result = <number>_.indexOf([1, 1, 2, 2, 3, 3], 2, true);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
//WHAT'S LEFT
|
||||
@@ -165,12 +181,6 @@ _.last([5, 4, 3, 2, 1]);
|
||||
|
||||
|
||||
|
||||
_.flatten([1, 2, 3, 4]);
|
||||
_.flatten([1, <any>[2]]);
|
||||
|
||||
// typescript doesn't like the elements being different
|
||||
_.flatten([1, [2], <any>[3, <any>[[4]]]]);
|
||||
_.flatten([1, [2], <any>[3, <any>[[4]]]], true);
|
||||
_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
|
||||
_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
|
||||
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
|
||||
@@ -179,7 +189,7 @@ _.uniq([1, 2, 1, 3, 1, 4]);
|
||||
_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
|
||||
var r = _.object<{ [key: string]: number }>(['moe', 'larry', 'curly'], [30, 40, 50]);
|
||||
_.object([[<any>'moe', 30], [<any>'larry', 40], [<any>'curly', 50]]);
|
||||
_.indexOf([1, 2, 3], 2);
|
||||
|
||||
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
|
||||
_.sortedIndex([10, 20, 30, 40, 50], 35);
|
||||
_.range(10);
|
||||
|
||||
Vendored
+19
-11
@@ -959,27 +959,35 @@ declare module _ {
|
||||
values?: any): TResult;
|
||||
|
||||
/**
|
||||
* Returns the index at which value can be found in the array, or -1 if value is not present in the array.
|
||||
* Uses the native indexOf function unless it's missing. If you're working with a large array, and you know
|
||||
* that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number
|
||||
* as the third argument in order to look for the first matching value in the array after the given index.
|
||||
* @param array The array to search for the index of `value`.
|
||||
* @param value The value to search for within `array`.
|
||||
* @param isSorted True if the array is already sorted, optional, default = false.
|
||||
* Gets the index at which the first occurrence of value is found using strict equality
|
||||
* for comparisons, i.e. ===. If the array is already sorted providing true for fromIndex
|
||||
* will run a faster binary search.
|
||||
* @param array The array to search.
|
||||
* @param value The value to search for.
|
||||
* @param fromIndex The index to search from.
|
||||
* @return The index of `value` within `array`.
|
||||
**/
|
||||
export function indexOf<T>(
|
||||
array: List<T>,
|
||||
value: T,
|
||||
isSorted?: boolean): number;
|
||||
value: T): number;
|
||||
|
||||
/**
|
||||
* @see _indexof
|
||||
* @see _.indexOf
|
||||
* @param fromIndex The index to search from
|
||||
**/
|
||||
export function indexOf<T>(
|
||||
array: List<T>,
|
||||
value: T,
|
||||
startFrom: number): number;
|
||||
fromIndex: number): number;
|
||||
|
||||
/**
|
||||
* @see _.indexOf
|
||||
* @param isSorted True to perform a binary search on a sorted array.
|
||||
**/
|
||||
export function indexOf<T>(
|
||||
array: List<T>,
|
||||
value: T,
|
||||
isSorted: boolean): number;
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the
|
||||
|
||||
Reference in New Issue
Block a user