The natural sequel to deep clone: instead of copying a structure, compare two. It probes the same edge-case awareness.
Object.is catches the easy wins — primitives, and the tricky NaN/signed-zero cases === gets wrong.Object.keys covers array indices, but compare Array.isArray if you want strict type matching.getTime() / entries.WeakMap/Set of visited pairs to avoid infinite recursion.Write the base version, then extend it to handle Date and arrays-vs-objects type mismatches.
function deepEqual(a, b) { // your code here } console.log(deepEqual({ x: 1, y: [2, 3] }, { x: 1, y: [2, 3] })); // true console.log(deepEqual({ x: 1 }, { x: 1, y: 2 })); // false
Test Code
Enter JavaScript that runs after your solution. It should return a value or a Promise.