Array Wrapper Class
Easy
188
8
37.3% Acceptance
In this lab, you will create an ArrayWrapper
class that accepts an array of integers in its constructor. The class should have the following features:
- When two instances of this class are added together with the
+
operator, the resulting value is the sum of all the elements in both arrays. - When the
String()
function is called on the instance, it will return a comma-separated string surrounded by brackets. For example,[1,2,3]
.
Example1:
const obj1 = new ArrayWrapper([1,2]); const obj2 = new ArrayWrapper([3,4]); console.log(obj1 + obj2); // Output: 10
Example 2:
const obj = new ArrayWrapper([23,98,42,70]); console.log(String(obj)); // Output: "[23,98,42,70]"
Example 3:
const obj1 = new ArrayWrapper([]); const obj2 = new ArrayWrapper([]); console.log(obj1 + obj2); // Output: 0
Constraints:
0 <= nums.length <= 1000
0 <= nums[i] <= 1000
- Note:
nums
is the array passed to the constructor
You have to add a
default export
for the Array Wrapper Class
Follow the instructions given in the initial lab material to implement the missing features and complete the necessary challenges. Remember to use ESM import/export and write bug-free code. Good luck!