JavaScript Deep Object Comparison: Two Approaches Quiz
Diff the keys of two plain objects two ways (JSON.stringify shortcut and a recursive walker), plus two companions on circular references and a Map-based structural diff.
Question Bank
Hard
JavaScript
quiz
references
immutability
interview-prep
642 views
17
Implement diffKeys(a, b) that returns the keys whose VALUES differ between a and b, plus any key that exists in one object but not the other, using a JSON.stringify-per-key shortcut. Assume both inputs are JSON-safe (no Dates, Maps, or functions).
Examples
Example 1:
Input:
person1 = { name: "foo", age: 21, hobbies: 45 }
person2 = { name: "foo", age: 45, height: 175, hobbies: 45, likes: 45 }
Output: ["age", "height", "likes"]
Explanation: age has different values; height and likes exist only in person2.3 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium