Deep Clone
Copy a nested structure so nothing is shared — including the cases that break a naive recursion.
JavaScript · ES6 — Pratik Rai ·
Compare two values structurally, because === only ever compares references.
Write deepEqual(a, b) returning whether the two values are structurally equal.
Two objects are equal when they have the same keys and every corresponding value is deeply equal; key order does not matter. Two arrays are equal when they have the same length and equal values in the same order. Primitives compare with ===, except that NaN equals NaN.
Input:
JSfile.javascript1deepEqual({ x: [1, 2] }, { x: [1, 2] });
Output:
true
Different objects, identical structure.
typeof null is "object", so it needs its own guard.Goal: Return true only when the two values match all the way down.
Continue learning with these related challenges
Copy a nested structure so nothing is shared — including the cases that break a naive recursion.
JavaScript · ES6 — Pratik Rai ·
Freeze an object all the way down, because Object.freeze only handles the top level.
JavaScript · ES6 — Pratik Rai ·
Group an array into buckets by a key function — now a real language feature as Object.groupBy.
JavaScript · ES6 — Pratik Rai ·
Copy a nested structure so nothing is shared — including the cases that break a naive recursion.
JavaScript · ES6
Pratik Rai ·
Freeze an object all the way down, because Object.freeze only handles the top level.
JavaScript · ES6
Pratik Rai ·
Group an array into buckets by a key function — now a real language feature as Object.groupBy.
JavaScript · ES6
Pratik Rai ·