The deepEqual function is supposed to take in 2 values in see if they are exactly the same. The results for the first and second test come back as expected. Is there perhaps something wrong with the way I'm incorporating the recursive call?
function deepEqual(obj1, obj2) {
if (typeof obj1 == 'object' && typeof obj1 !== null && typeof obj2 == 'object' && typeof obj2 !== null) {
if (obj1.length != obj2.length) {return false;}
for (var prop in obj1) {
if (typeof obj1[prop] == 'object') {deepEqual(obj1[prop], obj2[prop]);}
if (obj1[prop] != obj2[prop]) {return false;}
}
return true;
} else if (obj1 === obj2) {return true;}
else {return false;}
}
var obj = {here: {is: "an"}, object: 2};
console.log(deepEqual(obj, obj));
// → true -> true
console.log(deepEqual(obj, {here: 1, object: 2}));
// → false -> false
console.log(deepEqual(obj, {here: {is: "an"}, object: 2}));
// → true -> false