diff --git a/2695.array-wrapper.js b/2695.array-wrapper.js new file mode 100644 index 0000000..c671858 --- /dev/null +++ b/2695.array-wrapper.js @@ -0,0 +1,27 @@ +/** + * URL of this problem + * https://leetcode.com/problems/array-wrapper/ + */ + +/** + * @param {number[]} nums + */ +var ArrayWrapper = function (nums) { + this.nums = nums; +}; + +ArrayWrapper.prototype.valueOf = function () { + return this.nums.reduce((acc, cur) => acc + cur, 0); +}; + +ArrayWrapper.prototype.toString = function () { + return "[" + this.nums.toString() + "]"; +}; + +/** + * const obj1 = new ArrayWrapper([1,2]); + * const obj2 = new ArrayWrapper([3,4]); + * obj1 + obj2; // 10 + * String(obj1); // "[1,2]" + * String(obj2); // "[3,4]" + */ diff --git a/2703.return-length-of-arguments-passed.js b/2703.return-length-of-arguments-passed.js new file mode 100644 index 0000000..01a75ba --- /dev/null +++ b/2703.return-length-of-arguments-passed.js @@ -0,0 +1,15 @@ +/** + * URL of this problem + * https://leetcode.com/problems/return-length-of-arguments-passed/ + */ + +/** + * @return {number} + */ +var argumentsLength = function (...args) { + return [...args].length; +}; + +/** + * argumentsLength(1, 2, 3); // 3 + */