diff --git a/src/compat/array/find.ts b/src/compat/array/find.ts index 7c57bd68b..0b66dc70c 100644 --- a/src/compat/array/find.ts +++ b/src/compat/array/find.ts @@ -91,7 +91,7 @@ export function find( * Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey. * * @template T - * @param source - The source array or object to search through. + * @param collection - The source array or object to search through. * @param [doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name. * @param [fromIndex=0] - The index to start the search from, defaults to 0. * @returns The first property value that has the specified property, or `undefined` if no match is found. @@ -103,7 +103,7 @@ export function find( * console.log(result); // { id: 1, name: 'Alice' } */ export function find( - source: ArrayLike | Record | null | undefined, + collection: ArrayLike | Record | null | undefined, _doesMatch: | ((item: T, index: number, arr: any) => unknown) | Partial @@ -111,22 +111,22 @@ export function find( | PropertyKey = identity, fromIndex = 0 ): T | undefined { - if (!source) { + if (!collection) { return undefined; } if (fromIndex < 0) { - fromIndex = Math.max(source.length + fromIndex, 0); + fromIndex = Math.max(collection.length + fromIndex, 0); } const doesMatch = iteratee(_doesMatch); - if (!Array.isArray(source)) { - const keys = Object.keys(source) as Array; + if (!Array.isArray(collection)) { + const keys = Object.keys(collection) as Array; for (let i = fromIndex; i < keys.length; i++) { const key = keys[i]; - const value = source[key] as T; + const value = collection[key] as T; - if (doesMatch(value, key as number, source)) { + if (doesMatch(value, key as number, collection)) { return value; } } @@ -134,5 +134,5 @@ export function find( return undefined; } - return source.slice(fromIndex).find(doesMatch); + return collection.slice(fromIndex).find(doesMatch); }