Skip to content

Instantly share code, notes, and snippets.

@c7x43t
Last active February 14, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7x43t/65098d6149c54c32c1189d0923d43a42 to your computer and use it in GitHub Desktop.
Save c7x43t/65098d6149c54c32c1189d0923d43a42 to your computer and use it in GitHub Desktop.
function deepCompare(o1, o2) {
if (typeof o1 !== "object" || o1 === null) return o1 === o2; // fast obj/null test
let n;
if (o1 instanceof Array) { // fast array test
const l = o1.length;
for (let i = 0; i < l; i++) {
if (deepCompare(o1[i], o2[i])) {} else {
return false
}
}
return true;
}
for (let i in o1) {
if (!!o1[i] && deepCompare(o1[i], o2[i])) {} else { // fast hasProperty test
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment