Compare Values Deeply

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write deepEqual(a, b), returning true when two values hold the same data and false otherwise. Compare primitives with ===, except that NaN equals NaN. Two arrays are equal when they have the same length and equal items in the same order. Two plain objects are equal when they have the same own keys, in any order, with equal values, so a key holding undefined still has to be on both sides. Two Dates are equal when they hold the same time. Values of different kinds are never equal: an array never equals a plain object, a Date never equals a plain object, and null equals only null. Arrays and objects can be nested to any depth.

Your code must pass

  • Compares primitives, with NaN equal to itself
  • Compares arrays item by item, in order
  • Compares objects by keys and values, in any key order
  • Compares nested objects and arrays
  • Compares Dates by their time