{ "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\nYou may assume the object or array is the output of JSON.parse
.
\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\nobj
is a valid JSON object or array2 <= JSON.stringify(obj).length <= 105
\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
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 5.1.6, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2022 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }