{ "data": { "question": { "questionId": "2735", "questionFrontendId": "2628", "categoryTitle": "JavaScript", "boundTopicId": 2222277, "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": "完全相等的 JSON 字符串", "translatedContent": "

给定两个对象 o1o2 ,请你检查它们是否 完全相等

\n\n

对于两个 完全相等 的对象,它们必须包含相同的键,并且相关的值也必须 完全相等 。如果两个对象通过了 === 相等性检查,它们也被认为是 完全相等 的。

\n\n

你可以假设这两个对象都是 JSON.parse 的输出。换句话说,它们是有效的 JSON

\n\n

请你在不使用 lodash 的 _.isEqual() 函数的前提下解决这个问题。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:o1 = {\"x\":1,\"y\":2}, o2 = {\"x\":1,\"y\":2}\n输出:true\n输入:键和值完全匹配。\n
\n\n

示例 2:

\n\n
\n输入:o1 = {\"y\":2,\"x\":1}, o2 = {\"x\":1,\"y\":2}\n输出:true\n解释:尽管键的顺序不同,但它们仍然完全匹配。\n
\n\n

示例 3:

\n\n
\n输入:o1 = {\"x\":null,\"L\":[1,2,3]}, o2 = {\"x\":null,\"L\":[\"1\",\"2\",\"3\"]}\n输出:false\n解释:数字数组不同于字符串数组。\n
\n\n

示例 4:

\n\n
\n输入:o1 = true, o2 = false\n输出:false\n解释:true !== false
\n\n

 

\n\n

提示:

\n\n\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 0, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}", "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\": \"158\", \"totalSubmission\": \"503\", \"totalAcceptedRaw\": 158, \"totalSubmissionRaw\": 503, \"acRate\": \"31.4%\"}", "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, "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 4.5.4<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "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", "__typename": "QuestionNode" } } }