Array Wrapper Class
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,
const obj1 = new ArrayWrapper([1,2]); const obj2 = new ArrayWrapper([3,4]); console.log(obj1 + obj2); // Output: 10
const obj = new ArrayWrapper([23,98,42,70]); console.log(String(obj)); // Output: "[23,98,42,70]"
const obj1 = new ArrayWrapper(); const obj2 = new ArrayWrapper(); console.log(obj1 + obj2); // Output: 0
0 <= nums.length <= 1000
0 <= nums[i] <= 1000
numsis the array passed to the constructor
You have to add a
default exportfor 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!