Created
August 5, 2019 18:32
-
-
Save anteriovieira/29e981ef3d17b138edefee5da0fba2c2 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
const equals = (a, b) => { | |
if (a === b) return true; | |
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime(); | |
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object')) return a === b; | |
if (a === null || a === undefined || b === null || b === undefined) return false; | |
if (a.prototype !== b.prototype) return false; | |
let keys = Object.keys(a); | |
if (keys.length !== Object.keys(b).length) return false; | |
return keys.every(k => equals(a[k], b[k])); | |
}; | |
console.log(equals({ a: 1, b: 2}, { b: 2, a: 1})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment