JavaScript interview: Implement deepEqual

medium
objects
recursion

Write deepEqual(a, b). Primitives are equal if Object.is(a, b) (so NaN equals NaN). Arrays are equal if they have the same length and equal items. Plain objects are equal if they have the same keys with equal values, in any order.

An array is never equal to an object, even [] and {}.

Your code

Runs in a Web Worker in your browser. Tests use real timers, so a run takes a second or two.

FAQ