@@ -103,36 +103,32 @@ export function find<T extends object>(
103103 * console.log(result); // { id: 1, name: 'Alice' }
104104 */
105105export function find < T > (
106- source : ArrayLike < T > | Record < any , any > | null | undefined ,
107- _doesMatch :
108- | ( ( item : T , index : number , arr : any ) => unknown )
109- | Partial < T >
110- | [ keyof T , unknown ]
111- | PropertyKey = identity ,
106+ collection : ArrayLike < T > | Record < any , any > | null | undefined ,
107+ predicate : ( ( item : T , index : number , arr : any ) => unknown ) | Partial < T > | [ keyof T , unknown ] | PropertyKey = identity ,
112108 fromIndex = 0
113109) : T | undefined {
114- if ( ! source ) {
110+ if ( ! collection ) {
115111 return undefined ;
116112 }
117113 if ( fromIndex < 0 ) {
118- fromIndex = Math . max ( source . length + fromIndex , 0 ) ;
114+ fromIndex = Math . max ( collection . length + fromIndex , 0 ) ;
119115 }
120116
121- const doesMatch = iteratee ( _doesMatch ) ;
122- if ( ! Array . isArray ( source ) ) {
123- const keys = Object . keys ( source ) as Array < keyof T > ;
117+ const doesMatch = iteratee ( predicate ) ;
118+ if ( ! Array . isArray ( collection ) ) {
119+ const keys = Object . keys ( collection ) as Array < keyof T > ;
124120
125121 for ( let i = fromIndex ; i < keys . length ; i ++ ) {
126122 const key = keys [ i ] ;
127- const value = source [ key ] as T ;
123+ const value = collection [ key ] as T ;
128124
129- if ( doesMatch ( value , key as number , source ) ) {
125+ if ( doesMatch ( value , key as number , collection ) ) {
130126 return value ;
131127 }
132128 }
133129
134130 return undefined ;
135131 }
136132
137- return source . slice ( fromIndex ) . find ( doesMatch ) ;
133+ return collection . slice ( fromIndex ) . find ( doesMatch ) ;
138134}
0 commit comments