JavaScript Utilities
Deep Equality Comparison
mediumJS SpecificJS / TS12 tests
Problem Statement
Implement a function `deepEqual(a, b)` that performs a deep comparison between two values to determine if they are equivalent. Two values are deeply equal if: 1. They are strictly equal primitives (`===`), with the exception that `NaN` is equal to `NaN`. 2. Both are arrays of the same length, and elements at corresponding indices are deeply equal. 3. Both are plain objects with the same set of keys, and values for each key are deeply equal. 4. Different types, functions, null vs undefined, or unequal structures must return `false`.
Examples
Example 1:
Input: a = { x: 1, y: [2, 3] }, b = { x: 1, y: [2, 3] }
Output: true
Example 2:
Input: a = [1, 2], b = [1, 3]
Output: false
Example 3:
Input: a = { a: 1 }, b = { a: 1, b: undefined }
Output: falseJavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
12 test cases. No second person needed.