Skip to content

Commit 316384d

Browse files
authored
Fix #2 - isEqual not working when a differing value is found as 0 (#3)
1 parent 1d1230a commit 316384d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/isEqual.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ export function isEqual(a: EqualityType, b: EqualityType): boolean {
2525
if (Array.isArray(a)) {
2626
return (
2727
a.length === (b as IndividualEqualityType[]).length &&
28-
!a.find((value, index) => !isEqual(value, (b as IndividualEqualityType[])[index]))
28+
isNullOrUndefined(a.find((value, index) => !isEqual(value, (b as IndividualEqualityType[])[index])))
2929
);
3030
} else if (typeof a === 'object') {
3131
const keysA = Object.keys(a as object).sort();
3232
const keysB = Object.keys(b as object).sort();
3333

34-
if (isEqual(keysA, keysB) && !Object.entries(a as object).find(([key, value]) => !isEqual((b as object)[key], value))) {
34+
if (
35+
isEqual(keysA, keysB) &&
36+
isNullOrUndefined(Object.entries(a as object).find(([key, value]) => !isEqual((b as object)[key], value)))
37+
) {
3538
return true;
3639
}
3740
}

tests/isEqual.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ describe('isEqual', () => {
178178

179179
expect(isEqual(a, b)).toBe(false);
180180
});
181+
182+
it('differing number arrays are not equal', () => {
183+
const a = [23, 0];
184+
const b = [23, 61];
185+
186+
expect(isEqual(a, b)).toBe(false);
187+
});
181188
});
182189

183190
describe('objects', () => {

0 commit comments

Comments
 (0)