{ "data": { "question": { "questionId": "2805", "questionFrontendId": "2695", "categoryTitle": "JavaScript", "boundTopicId": 2275511, "title": "Array Wrapper", "titleSlug": "array-wrapper", "content": "

Create a class ArrayWrapper that accepts an array of integers in its constructor. This class should have two features:

\n\n\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [[1,2],[3,4]], operation = "Add"\nOutput: 10\nExplanation:\nconst obj1 = new ArrayWrapper([1,2]);\nconst obj2 = new ArrayWrapper([3,4]);\nobj1 + obj2; // 10\n
\n\n

Example 2:

\n\n
\nInput: nums = [[23,98,42,70]], operation = "String"\nOutput: "[23,98,42,70]"\nExplanation:\nconst obj = new ArrayWrapper([23,98,42,70]);\nString(obj); // "[23,98,42,70]"\n
\n\n

Example 3:

\n\n
\nInput: nums = [[],[]], operation = "Add"\nOutput: 0\nExplanation:\nconst obj1 = new ArrayWrapper([]);\nconst obj2 = new ArrayWrapper([]);\nobj1 + obj2; // 0\n
\n\n

 

\n

Constraints:

\n\n\n", "translatedTitle": "包装数组", "translatedContent": "

创建一个名为 ArrayWrapper 的类,它在其构造函数中接受一个整数数组作为参数。该类应具有以下两个特性:

\n\n\n\n

 

\n\n

示例 1:

\n\n
\n输入:nums = [[1,2],[3,4]], operation = \"Add\"\n输出:10\n解释:\nconst obj1 = new ArrayWrapper([1,2]);\nconst obj2 = new ArrayWrapper([3,4]);\nobj1 + obj2; // 10\n
\n\n

示例 2:

\n\n
\n输入:nums = [[23,98,42,70]], operation = \"String\"\n输出:\"[23,98,42,70]\"\n解释:\nconst obj = new ArrayWrapper([23,98,42,70]);\nString(obj); // \"[23,98,42,70]\"\n
\n\n

示例 3:

\n\n
\n输入:nums = [[],[]], operation = \"Add\"\n输出:0\n解释:\nconst obj1 = new ArrayWrapper([]);\nconst obj2 = new ArrayWrapper([]);\nobj1 + obj2; // 0\n
\n\n

 

\n\n

提示:

\n\n\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 3, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void}\n */\nvar ArrayWrapper = function(nums) {\n \n};\n\n/**\n * @return {number}\n */\nArrayWrapper.prototype.valueOf = function() {\n \n}\n\n/**\n * @return {string}\n */\nArrayWrapper.prototype.toString = function() {\n \n}\n\n/**\n * const obj1 = new ArrayWrapper([1,2]);\n * const obj2 = new ArrayWrapper([3,4]);\n * obj1 + obj2; // 10\n * String(obj1); // \"[1,2]\"\n * String(obj2); // \"[3,4]\"\n */", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "class ArrayWrapper {\n \n\tconstructor(nums: number[]) {\n \n }\n\n\tvalueOf(): number {\n \n }\n\n\ttoString(): string {\n \n }\n};\n\n/**\n * const obj1 = new ArrayWrapper([1,2]);\n * const obj2 = new ArrayWrapper([3,4]);\n * obj1 + obj2; // 10\n * String(obj1); // \"[1,2]\"\n * String(obj2); // \"[3,4]\"\n */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"2.7K\", \"totalSubmission\": \"3.5K\", \"totalAcceptedRaw\": 2706, \"totalSubmissionRaw\": 3481, \"acRate\": \"77.7%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "[[1,2],[3,4]]\n\"Add\"", "metaData": "{\n \"name\": \"ArrayWrapper\",\n \"params\": [\n {\n \"name\": \"nums\",\n \"type\": \"integer[][]\"\n },\n {\n \"type\": \"string\",\n \"name\": \"operation\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\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 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/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": "[[1,2],[3,4]]\n\"Add\"\n[[23,98,42,70]]\n\"String\"\n[[],[]]\n\"Add\"", "__typename": "QuestionNode" } } }