diff --git a/benchmarks/performance/omitBy.bench.ts b/benchmarks/performance/omitBy.bench.ts index dd439d40..00964900 100644 --- a/benchmarks/performance/omitBy.bench.ts +++ b/benchmarks/performance/omitBy.bench.ts @@ -6,15 +6,14 @@ const omitByToolkit = omitByToolkit_; const omitByLodash = omitByLodash_; describe('omitBy', () => { + const obj = { a: 1, b: 'omit', c: 3, d: 'test', e: 0 }; + const shouldOmit = (value: number | string) => typeof value === 'string'; + bench('es-toolkit/omitBy', () => { - const obj = { a: 1, b: 'omit', c: 3 }; - const shouldOmit = (value: number | string) => typeof value === 'string'; omitByToolkit(obj, shouldOmit); }); bench('lodash/omitBy', () => { - const obj = { a: 1, b: 'omit', c: 3 }; - const shouldOmit = (value: number | string) => typeof value === 'string'; omitByLodash(obj, shouldOmit); }); }); diff --git a/src/compat/object/omit.ts b/src/compat/object/omit.ts index 0dffbe71..ff16859f 100644 --- a/src/compat/object/omit.ts +++ b/src/compat/object/omit.ts @@ -30,7 +30,7 @@ export function omit, K extends keyof T>(obj: T, k * * @template T - The type of object. * @param {T} obj - The object to omit keys from. - * @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object. + * @param {...(PropertyKey | PropertyKey[] | PropertyKey[][])} keys - A variable number of keys to be omitted from the object. * @returns {Partial} A new object with the specified keys omitted. */ export function omit< diff --git a/src/object/omitBy.ts b/src/object/omitBy.ts index 997c971b..2e8cf989 100644 --- a/src/object/omitBy.ts +++ b/src/object/omitBy.ts @@ -13,7 +13,7 @@ * * @example * const obj = { a: 1, b: 'omit', c: 3 }; - * const shouldOmit = (key, value) => typeof value === 'string'; + * const shouldOmit = (value) => typeof value === 'string'; * const result = omitBy(obj, shouldOmit); * // result will be { a: 1, c: 3 } */ @@ -23,9 +23,11 @@ export function omitBy>( ): Partial { const result: Partial = {}; - const objEntries = Object.entries(obj); - for (let i = 0; i < objEntries.length; i++) { - const [key, value] = objEntries[i]; + const keys = Object.keys(obj); + + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const value = obj[key]; if (!shouldOmit(value, key)) { (result as any)[key] = value; }