Skip to content

Commit 65db578

Browse files
committed
Add solution #2695
1 parent 6547af2 commit 65db578

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@
399399
2666|[Allow One Function Call](./2666-allow-one-function-call.js)|Easy|
400400
2667|[Create Hello World Function](./2667-create-hello-world-function.js)|Easy|
401401
2677|[Chunk Array](./2677-chunk-array.js)|Easy|
402+
2695|[Array Wrapper](./2695-array-wrapper.js)|Easy|
402403
2703|[Return Length of Arguments Passed](./2703-return-length-of-arguments-passed.js)|Easy|
403404
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
404405
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|

solutions/2695-array-wrapper.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 2695. Array Wrapper
3+
* https://leetcode.com/problems/array-wrapper/
4+
* Difficulty: Easy
5+
*
6+
* Create a class ArrayWrapper that accepts an array of integers in its constructor.
7+
*
8+
* This class should have two features:
9+
* - When two instances of this class are added together with the + operator, the resulting
10+
* value is the sum of all the elements in both arrays.
11+
* - When the String() function is called on the instance, it will return a comma separated
12+
* string surrounded by brackets. For example, [1,2,3].
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {void}
18+
*/
19+
var ArrayWrapper = function(nums) {
20+
this.nums = nums;
21+
};
22+
23+
/**
24+
* @return {number}
25+
*/
26+
ArrayWrapper.prototype.valueOf = function() {
27+
return this.nums.reduce((sum, n) => sum + n, 0);
28+
};
29+
30+
/**
31+
* @return {string}
32+
*/
33+
ArrayWrapper.prototype.toString = function() {
34+
return JSON.stringify(this.nums);
35+
};

0 commit comments

Comments
 (0)