{ "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.

\n\n

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.

\n\n

You may assume both objects are the output of JSON.parse. In other words, they are valid JSON.

\n\n

Please solve it without using lodash's _.isEqual() function.

\n\n

 

\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\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 13, "dislikes": 1, "isLiked": null, "similarQuestions": "[{\"title\": \"Convert Object to JSON String\", \"titleSlug\": \"convert-object-to-json-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Flatten Deeply Nested Array\", \"titleSlug\": \"flatten-deeply-nested-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", "exampleTestcases": "{\"x\":1,\"y\":2}\n{\"x\":1,\"y\":2}\n{\"y\":2,\"x\":1}\n{\"x\":1,\"y\":2}\n{\"x\":null,\"L\":[1,2,3]}\n{\"x\":null,\"L\":[\"1\",\"2\",\"3\"]}\ntrue\nfalse", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {any} o1\n * @param {any} o2\n * @return {boolean}\n */\nvar areDeeplyEqual = function(o1, o2) {\n \n};", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "function areDeeplyEqual(o1: any, o2: any): boolean {\n\n};", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"285\", \"totalSubmission\": \"860\", \"totalAcceptedRaw\": 285, \"totalSubmissionRaw\": 860, \"acRate\": \"33.1%\"}", "hints": [ "You can check if a value is an array with the Array.isArray() method. You can check if a value is an object by saying typeof obj === 'object' && obj !== null. You can list the keys of an object with the Object.keys() function.", "If two objects have different keys or two arrays have a different length, they cannot be equal.", "You can use recursion to investigate if the values of an object or array are also deeply equal. The base case is when the values are primitives (string, number, etc), at which case the check is a trivial === check." ], "solution": null, "status": null, "sampleTestCase": "{\"x\":1,\"y\":2}\n{\"x\":1,\"y\":2}", "metaData": "{\n \"name\": \"areDeeplyEqual\",\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"o1\"\n },\n {\n \"type\": \"string\",\n \"name\": \"o2\"\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For 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.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2020 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }