2805. Array Wrapper
My accepted JavaScript solution to LeetCode problem 2805, Array Wrapper, running in 50ms.
- Difficulty: Easy
- JavaScript
- Runtime 50ms
- Memory 53.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 50ms, memory 53.9MB, accepted 2026-01-01.
/**
* @param {number[]} nums
* @return {void}
*/
var ArrayWrapper = function(nums) {
this.nums = nums;
};
/**
* @return {number}
*/
ArrayWrapper.prototype.valueOf = function() {
return this.nums.reduce((sum, num) => sum + num, 0);
}
/**
* @return {string}
*/
ArrayWrapper.prototype.toString = function() {
return "[" + this.nums.join(",") + "]";
}
/**
* const obj1 = new ArrayWrapper([1,2]);
* const obj2 = new ArrayWrapper([3,4]);
* obj1 + obj2; // 10
* String(obj1); // "[1,2]"
* String(obj2); // "[3,4]"
*/