💾deepEqual()
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ function ⟩ recursive ⟩ deepEqual()
returns true only if they are
the same value or
objects with properties of the same keys/values, where the values are compared with a recursive call to deepEqual.
replit ⟩ deepEqual(a, b)
function deepEqual(a, b) {
// check if `value` is (non-function) object
function isNonFunctionObject(value) {
return typeof value === 'object' && value !== null;
}
💈範例:
// test
let obj = {
x: {y: "a"},
z: 2,
};
[
[x => x, x => x], // ⨉ (different functions)
[obj, obj], // ○ (same object)
[obj, {x: 1, z: 2}], // ⨉
[obj, {x: {y: "a"}, z: 2}], // ○
[1, 2], // ⨉
[1, 1], // ○
[obj, 1], // ⨉
[{x: undefined}, {}], // ⨉
].forEach(([a,b]) => {
console.log(deepEqual(a,b)) // ✅ test "deepEqual"
});