Loading homepage
Implement deepEqual(left, right) to compare values by their contents rather than only their references. Walk nested arrays and plain objects and decide whether both structures contain the same values.
This exercise focuses on primitives, arrays, and plain objects. Arrays can be sparse, so an absent slot is different from a present slot containing undefined.
Input: deepEqual({ scores: [2, { passed: true }] }, { scores: [2, { passed: true }] }); Output: true
Input: deepEqual({ value: undefined }, {}); Output: false
Input: deepEqual(new Array(1), [undefined]); Output: false
Input: deepEqual(NaN, NaN); Output: true
The JavaScript and TypeScript variants use the same API and behavior.