Skip to content

2695. Array Wrapper 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class ArrayWrapper {
  private nums: number[];

  constructor(nums: number[]) {
    this.nums = nums;
  }

  valueOf(): number {
    return this.nums.reduce((sum, num) => sum + num, 0);
  }

  toString(): string {
    return '[' + this.nums.join(',') + ']';
  }
}