Last active
July 22, 2022 20:55
-
-
Save themgoncalves/c2e58d2bff0960e094a00940ead74c5f 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
const deepCompare = (source, target) => { | |
if (typeOf(source) !== typeOf(target)) { | |
return false; | |
} | |
if (typeOf(source) === 'array') { | |
if (source.length !== target.length) { | |
return false; | |
} | |
return source.every((entry, index) => deepCompare(entry, target[index])) | |
} else if (typeOf(source) === 'object') { | |
if (Object.keys(source).length !== Object.keys(target).length) { | |
return false; | |
} | |
return Object.keys(source).every((key) => deepCompare(source[key], target[key])); | |
} else if (typeOf(source) === 'date') { | |
return source.getTime() === target.getTime(); | |
} | |
return source === target; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment