@carbon/ibm-products
Version:
Carbon for IBM Products
31 lines (29 loc) • 983 B
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
//#region src/global/js/utils/deepCompareObject.ts
/**
* Copyright IBM Corp. 2025, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const deepCompareObject = (a, b) => {
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) if (!deepCompareObject(a[i], b[i])) return false;
return true;
}
if (typeof a === "object" && a !== null && b !== null) {
if (!(typeof b === "object")) return false;
if (Object.keys(a).length !== Object.keys(b).length) return false;
for (const key in a) if (!deepCompareObject(a[key], b[key])) return false;
return true;
}
return a === b;
};
//#endregion
exports.deepCompareObject = deepCompareObject;