Array Wrapper

ClassesCoercion

Build an ArrayWrapper class taking an array of numbers.

Adding two instances with + gives the sum of every number in both. Passing one to String() gives the numbers comma-separated inside square brackets.

Examples

Example 1
Input
const a = new ArrayWrapper([1, 2]);
const b = new ArrayWrapper([3, 4]);
a + b;      // 10
String(a);
Output
"[1,2]"
Explanation
valueOf answers the numeric context, toString the string one.

Constraints

  • 0 <= nums.length <= 1000

Notes

  • Define only one of the two and the other context falls back to "[object Object]".

Hints

Read the full write-up for Array Wrapper
</>JavaScript
Loading editor…
Test Result
Run your code, or Submit to test it