I have a question about video “17- Exercise 3- Object Equality” in " The Ultimate JavaScript Mastery Series - Part 1" course.
Mosh’s textbook answer for the areEqual function is:
let address1 = new Address('a', 'b', 'c');
let address2 = new Address('a', 'b', 'c');
function areEqual(address1, address2) {
return address1.street === address2.street &&
address1.city === address2.street &&
address1.zipCode === address2.zipCode;
}
In contrast, I wrote:
function areEqual(address1, address2) {
for (let key in address1)
if (address1[key] !== address2[key])
return false;
return true;
}
My code appears to work, and seems cleaner and more extensible than Mosh’s answer. Is there anything wrong with my solution that I should consider?
Thanks!