Created
July 26, 2019 11:40
-
-
Save DanCouper/a0467b678b46c33aab115f00d28d9a16 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
/** | |
* Simple deep equal function. Note that this expects a JSON-like config object; | |
* it is not designed for anything more complex. | |
* | |
* @param {any} a | |
* @param {any} b | |
* @returns {boolean} | |
*/ | |
export function deepEqual(a, b) { | |
if (Object.is(a, b)) { | |
return true; | |
} else if (isObject(a) && isObject(b)) { | |
if (Object.keys(a).length !== Object.keys(b).length) { | |
return false; | |
} | |
for (let key in a) if (!deepEqual(a[key], b[key])) return false; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* @param {any} subject | |
* @returns {boolean} | |
*/ | |
export function isObject(subject) { | |
return subject instanceof Object && subject !== null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment