{ "data": { "question": { "questionId": "2805", "questionFrontendId": "2695", "boundTopicId": null, "title": "Array Wrapper", "titleSlug": "array-wrapper", "content": "
Create a class ArrayWrapper
that accepts an array of integers in it's constructor. This class should have two features:
+
operator, the resulting value is the sum of all the elements in both arrays.String()
function is called on the instance, it will return a comma separated string surrounded by brackets. For example, [1,2,3]
.\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\n0 <= nums.length <= 1000
0 <= nums[i] <= 1000
Note: nums is the array passed to the constructor
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 4.5.4, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2020 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }