{ "data": { "question": { "questionId": "2864", "questionFrontendId": "2727", "boundTopicId": null, "title": "Is Object Empty", "titleSlug": "is-object-empty", "content": "

Given an object or an array, return if it is empty.

\n\n\n\n

You may assume the object or array is the output of JSON.parse.

\n\n

 

\n

Example 1:

\n\n
\nInput: obj = {"x": 5, "y": 42}\nOutput: false\nExplanation: The object has 2 key-value pairs so it is not empty.\n
\n\n

Example 2:

\n\n
\nInput: obj = {}\nOutput: true\nExplanation: The object doesn't have any key-value pairs so it is empty.\n
\n\n

Example 3:

\n\n
\nInput: obj = [null, false, 0]\nOutput: false\nExplanation: The array has 3 elements so it is not empty.\n
\n\n

 

\n

Constraints:

\n\n\n\n

 

\nCan you solve it in O(1) time?", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 138, "dislikes": 7, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"x\": 5, \"y\": 42}\n{}\n[null, false, 0]", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {Object|Array} obj\n * @return {boolean}\n */\nvar isEmpty = function(obj) {\n \n};", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Obj = Record | JSONValue[]\n\nfunction isEmpty(obj: Obj): boolean {\n\t\n};", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"27.7K\", \"totalSubmission\": \"35.7K\", \"totalAcceptedRaw\": 27708, \"totalSubmissionRaw\": 35742, \"acRate\": \"77.5%\"}", "hints": [], "solution": { "id": "1993", "canSeeDetail": true, "paidOnly": false, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"x\": 5, \"y\": 42}", "metaData": "{\n \"name\": \"isEmpty\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"manual\": true,\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ]\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 5.1.6, Node.js 16.13.2.

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

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

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

lodash.js library is included by default.

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