function isObject(obj) {
return (typeof obj === 'object' && obj !== null);
}
function isEqual(obj1, obj2) {
if (!isObject(obj1) || !isObject(obj2)) {
return obj1 === obj2;
}
if (obj1 === obj2) return true;
const obj1KeysLength = Object.keys(obj1).length;
const obj2KeysLength = Object.keys(obj2).length;
if (obj1KeysLength !== obj2KeysLength) return false;
for (let key in obj1) {
const result = isEqual(obj1[key], obj2[key]);
if(!result) return false;
}
return true;
}
const obj1 = {a:1,b:{x:100,y:200}}
const obj2 = {a:1,b:{x:100,y:200}}
isEqual(obj1, obj2) === true