@@ -24,7 +24,7 @@ type Obj = string | Record<string, string>
24
24
*/
25
25
type SortedIndexByComparator = ( leftObject : Obj , leftValue : string , rightObject : Obj , rightValue : string ) => number
26
26
27
- type SortedIndexOptions = {
27
+ interface SortedIndexOptions {
28
28
comparator ?: SortedIndexByComparator
29
29
reverse ?: boolean
30
30
}
@@ -44,11 +44,6 @@ export const DEFAULT_COMPARATOR = (left: string, right: string): number => {
44
44
)
45
45
}
46
46
47
- /**
48
- * Declare function used in sortedIndexBy for creating the iteratee.
49
- */
50
- type SortedIndexByIteratee = ( value : string | Record < string , string > ) => string
51
-
52
47
/**
53
48
* Given a list of elements, and a value to be added to the list, we
54
49
* perform a simple binary search of the list to determine the next
@@ -68,12 +63,19 @@ type SortedIndexByIteratee = (value: string | Record<string, string>) => string
68
63
* @param comparator - function used to compare the newValue with otherValues in the list
69
64
* @return sorted index
70
65
*/
71
- export function sortedIndexBy ( array : Obj [ ] , value : Obj , iteratee : SortedIndexByIteratee , options : SortedIndexOptions = { } ) : number {
66
+ export function sortedIndexBy (
67
+ array : Obj [ ] ,
68
+ value : Obj ,
69
+ iteratee : ( value : Obj ) => string ,
70
+ options : SortedIndexOptions = { }
71
+ ) : number {
72
72
if ( array . length === 0 ) {
73
73
return 0
74
74
}
75
75
// If given a function, use it. Otherwise, simply use locale sort with numeric enabled
76
- const comparatorFunction = options . comparator || ( ( leftObject , leftValue , rightObject , rightValue ) => DEFAULT_COMPARATOR ( leftValue , rightValue ) )
76
+ const comparatorFunction : SortedIndexByComparator = options . comparator || (
77
+ ( leftObject , leftValue , rightObject , rightValue ) => DEFAULT_COMPARATOR ( leftValue , rightValue )
78
+ )
77
79
let low = 0
78
80
let high = array . length
79
81
0 commit comments