Querying Object Equivalence:
I find myself struggling to comprehend the flow of my code and how I can rectify it.
Within the areEqual function, I am comparing the "value" property of two objects.
If they match -> isEqual=true -> continue with the loop If any values do not match -> isEqual = false and exit from the loop.
Nevertheless, I'm not achieving the expected outcomes. What specific logic am I failing to grasp here?
function Address (street, city, zipCode) {
this.street = street;
this.city = city;
this.zipCode = zipCode;
}
let address1 = new Address('a', 'b', 'c');
let address2 = new Address('a', 'd', 'c');
//checking equality between two objects
function areEqual(address1, address2){
let isEqual = true;
for(let key in address1) {
if(address1[key] === address2[key])
isEqual = true;
else
isEqual = false
break;
}
if(isEqual) return 'They are equal';
else return 'They are not equal';
}
console.log(areEqual(address1, address2));