From f820edacdb3e50fa38e2f610dec23bc04d3db25d Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:49:43 -0500 Subject: [PATCH] Time: 48 ms (83.37%), Space: 49.2 MB (97.22%) - LeetHub --- 2695-array-wrapper/2695-array-wrapper.js | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2695-array-wrapper/2695-array-wrapper.js diff --git a/2695-array-wrapper/2695-array-wrapper.js b/2695-array-wrapper/2695-array-wrapper.js new file mode 100644 index 0000000..4eeace6 --- /dev/null +++ b/2695-array-wrapper/2695-array-wrapper.js @@ -0,0 +1,29 @@ +/** + * @param {number[]} nums + * @return {void} + */ +var ArrayWrapper = function(nums) { + this.nums = nums +}; + +/** + * @return {number} + */ +ArrayWrapper.prototype.valueOf = function() { + return this.nums.reduce((a,b) => a + b, 0) +} + +/** + * @return {string} + */ +ArrayWrapper.prototype.toString = function() { + return JSON.stringify(this.nums) +} + +/** + * const obj1 = new ArrayWrapper([1,2]); + * const obj2 = new ArrayWrapper([3,4]); + * obj1 + obj2; // 10 + * String(obj1); // "[1,2]" + * String(obj2); // "[3,4]" + */ \ No newline at end of file