Skip to content

Instantly share code, notes, and snippets.

@DanCouper
Created July 26, 2019 11:40
Show Gist options
  • Save DanCouper/a0467b678b46c33aab115f00d28d9a16 to your computer and use it in GitHub Desktop.
Save DanCouper/a0467b678b46c33aab115f00d28d9a16 to your computer and use it in GitHub Desktop.
/**
* 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