Skip to content

Commit

Permalink
fix: array with additional properties in deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Mar 7, 2024
1 parent 4a48695 commit dfc3335
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/lib/equals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ const internalEqual = (comp: (a: any, b: any) => boolean) => (a: any, b: any) =>
return false;
}

if (a.constructor === Object) {
if (a.constructor === Object || Array.isArray(a)) {
const entries1 = Object.entries(a);
const entries2 = Object.entries(b);
return (
entries1.length === entries2.length && entries1.every(([key, value]) => comp(value, b[key]))
);
}

if (Array.isArray(a)) {
return a.length === b.length && a.every((value, i) => comp(value, b[i]));
}

if (a instanceof Date) {
return a.getTime() === b.getTime();
}
Expand Down

0 comments on commit dfc3335

Please sign in to comment.