-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: option should display as selected even when value is an object
- Loading branch information
1 parent
3a61fcc
commit 8fb373f
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
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,37 @@ | ||
const objectsEqual = (obj1, obj2) => { | ||
// If both are strictly equal, return true | ||
if (obj1 === obj2) { | ||
return true | ||
} | ||
|
||
// If either is not an object or is null, return false (handles primitive types and null) | ||
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) { | ||
return false | ||
} | ||
|
||
// Get the keys of both objects | ||
const keys1 = Object.keys(obj1) | ||
const keys2 = Object.keys(obj2) | ||
|
||
// If they have a different number of keys, they're not equal | ||
if (keys1.length !== keys2.length) { | ||
return false | ||
} | ||
|
||
// Compare each key-value pair recursively | ||
for (let key of keys1) { | ||
// Check if both objects have the same key | ||
if (!keys2.includes(key)) { | ||
return false | ||
} | ||
|
||
// Recursively compare the values | ||
if (!objectsEqual(obj1[key], obj2[key])) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
export default objectsEqual |