Last active
February 14, 2018 15:38
-
-
Save c7x43t/65098d6149c54c32c1189d0923d43a42 to your computer and use it in GitHub Desktop.
This file contains 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 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