diff --git a/package.json b/package.json index 4b2f883c..e902a3a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "radash", - "version": "8.0.0", + "version": "8.0.1", "description": "Functional utility library - modern, simple, typed, powerful", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", diff --git a/src/array.ts b/src/array.ts index 3564b4c2..4594b827 100644 --- a/src/array.ts +++ b/src/array.ts @@ -395,7 +395,7 @@ export const diff = ( t as unknown as string | number | symbol ): T[] => { if (!root?.length && !other?.length) return [] - if (!root?.length) return [...other] + if (root?.length === undefined) return [...other] if (!other?.length) return [...root] const bKeys = other.reduce( (acc, item) => ({ diff --git a/src/tests/array.test.ts b/src/tests/array.test.ts index ed67999a..065e7510 100644 --- a/src/tests/array.test.ts +++ b/src/tests/array.test.ts @@ -518,6 +518,14 @@ describe('array module', () => { const result = _.diff(null, null) assert.deepEqual(result, []) }) + test('handles empty array root', () => { + const result = _.diff([], ['a']) + assert.deepEqual(result, []) + }) + test('handles empty array other', () => { + const result = _.diff(['a'], []) + assert.deepEqual(result, ['a']) + }) test('returns all items from root that dont exist in other', () => { const result = _.diff( ['a', 'b', 'c'],