Hi,
Thanks for the post, it's really helpful!
I've just reformatted and refactored a bit your code, so now it's following ESLint standards.
export function compareObjects(obj1, obj2) { if (obj1 === obj2) return true; if ( typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 == null || obj2 == null ) { return false; } const keysA = Object.keys(obj1); const keysB = Object.keys(obj2); if (keysA.length !== keysB.length) { return false; } let result = true; keysA.forEach((key) => { if (!keysB.includes(key)) { result = false; } if ( typeof obj1[key] === 'function' || typeof obj2[key] === 'function' ) { if (obj1[key].toString() !== obj2[key].toString()) { result = false; } } if (!compareObjects(obj1[key], obj2[key])) { result = false; } }); return result; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi,
Thanks for the post, it's really helpful!
I've just reformatted and refactored a bit your code, so now it's following ESLint standards.