Home
← All questions

Deep-diff two nested JSON objects in JavaScript

HardPremiumJavaScript

Asked at Google

JavaScript interview practice: Compare two deeply nested objects and report each differing key as { from, to }. Missing keys show 'EMPTY'.

Problem

Write diff(a, b) that returns the set of differences between two deeply nested JSON objects. For each leaf key that changed, report { from, to }. If a key exists in only one object, the missing side is the string "EMPTY".

function diff(a, b) {
  // your code
}
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium