From 9e34b3d503f73ceac2949d6e929d81fce3ee690e Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 13 Oct 2013 18:58:35 -0400 Subject: [PATCH] definitions for _.indexOf --- lodash/lodash-tests.ts | 24 +++++++++++++++++------- lodash/lodash.d.ts | 30 +++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 915b1c96f..1c3401620 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -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 = _.compact([0, 1, false, 2, '', 3]); result = _.difference([1, 2, 3, 4, 5], [5, 2, 10]); @@ -88,6 +97,13 @@ result = _.take([1, 2, 3], function(num) { result = _.take(foodsOrganic, 'organic'); result = _.take(foodsType, { 'type': 'fruit' }); +result = _.flatten([1, [2], [3, [[4]]]]); +result = _.flatten([1, [2], [3, [[4]]]], true); +result = _.flatten(stoogesQuotes, 'quotes'); + +result = _.indexOf([1, 2, 3, 1, 2, 3], 2); +result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); +result = _.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, [2]]); - -// typescript doesn't like the elements being different -_.flatten([1, [2], [3, [[4]]]]); -_.flatten([1, [2], [3, [[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([['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); _.range(10); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e1e3db3ab..b5f6b882c 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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( array: List, - value: T, - isSorted?: boolean): number; + value: T): number; /** - * @see _indexof + * @see _.indexOf + * @param fromIndex The index to search from **/ export function indexOf( array: List, 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( + array: List, + 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