-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export function compareObjects(obj1: any, obj2: any): boolean { | ||
if (obj1 === obj2) { | ||
return true; | ||
} | ||
|
||
if (typeof obj1 !== typeof obj2 || typeof obj1 !== 'object' || obj1 === null || obj2 === null) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(obj1) !== Array.isArray(obj2)) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(obj1)) { | ||
if (obj1.length !== obj2.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < obj1.length; i++) { | ||
if (!compareObjects(obj1[i], obj2[i])) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
const keys1 = Object.keys(obj1); | ||
const keys2 = Object.keys(obj2); | ||
|
||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} | ||
|
||
for (let key of keys1) { | ||
if (!obj2.hasOwnProperty(key) || !compareObjects(obj1[key], obj2[key])) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
if (typeof obj1 === 'bigint' || typeof obj2 === 'bigint') { | ||
return BigInt(obj1) === BigInt(obj2); | ||
} | ||
|
||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters