From 17431f48c9b6ce63ed1587695ce8ba6ef5121fac Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 20 Dec 2024 22:46:35 -0500 Subject: [PATCH] document and format equals utility --- src/utils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils.js b/src/utils.js index 3acf1b1..e940f3f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -39,17 +39,17 @@ export function concat(aaa, bbb) { /** * Deep equality comparison - * - * @param {any} a - * @param {any} b - * @returns {boolean} + * + * @param {any} a First object to compare + * @param {any} b Second object to compare + * @returns {boolean} true if objects are equal */ export function equals(a, b) { - if (a === b) return true; - if (!a || !b || typeof a !== typeof b) return false; - return Array.isArray(a) + if (a === b) return true + if (!a || !b || typeof a !== typeof b) return false + return Array.isArray(a) ? a.length === b.length && a.every((v, i) => equals(v, b[i])) - : Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(k => equals(a[k], b[k])); + : Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(k => equals(a[k], b[k])) } /**