Last active
February 21, 2022 22:52
-
-
Save blarfoon/856e1e425d42d0e182b49eedac3fc22c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function areEqualShallow(a, b) { | |
for (const key in a) { | |
if (!(key in b) || a[key] !== b[key]) { | |
return false; | |
} | |
} | |
for (const key in b) { | |
if (!(key in a) || a[key] !== b[key]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
const myFirstObject = {}; | |
const mySecondObject = {}; | |
console.log(areEqualShallow(myFirstObject, mySecondObject)); // > true | |
myFirstObject.hi = "mom"; | |
mySecondObject.hi = "mom"; | |
console.log(areEqualShallow(myFirstObject, mySecondObject)); // > true | |
myFirstObject.nested = { | |
hi: "medium", | |
}; | |
mySecondObject.nested = { | |
hi: "medium", | |
}; | |
console.log(areEqualShallow(myFirstObject, mySecondObject)); // > false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment