{ "data": { "question": { "questionId": "2735", "questionFrontendId": "2628", "boundTopicId": null, "title": "JSON Deep Equal", "titleSlug": "json-deep-equal", "content": "
Given two objects o1
and o2
, check if they are deeply equal.
For two objects to be deeply equal, they must contain the same keys, and the associated values must also be deeply equal. Two objects are also considered deeply equal if they pass the ===
equality check.
You may assume both objects are the output of JSON.parse
. In other words, they are valid JSON.
Please solve it without using lodash's _.isEqual()
function.
\n
Example 1:
\n\n\nInput: o1 = {"x":1,"y":2}, o2 = {"x":1,"y":2}\nOutput: true\nExplanation: The keys and values match exactly.\n\n\n
Example 2:
\n\n\nInput: o1 = {"y":2,"x":1}, o2 = {"x":1,"y":2}\nOutput: true\nExplanation: Although the keys are in a different order, they still match exactly.\n\n\n
Example 3:
\n\n\nInput: o1 = {"x":null,"L":[1,2,3]}, o2 = {"x":null,"L":["1","2","3"]}\nOutput: false\nExplanation: The array of numbers is different from the array of strings.\n\n\n
Example 4:
\n\n\nInput: o1 = true, o2 = false\nOutput: false\nExplanation: true !== false\n\n
\n
Constraints:
\n\n1 <= JSON.stringify(o1).length <= 105
1 <= JSON.stringify(o2).length <= 105
maxNestingDepth <= 1000
Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES6 features.
lodash.js library is included by default.
\\r\\n\\r\\nFor Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.
\"], \"typescript\": [\"Typescript\", \"TypeScript 4.5.4, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2020 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }