Skip to content

Commit e4b9e32

Browse files
Merge pull request #2816 from chetannada/ltc-2652-js
Create 2652-sum-multiples.js
2 parents bdea6d0 + 0b996fe commit e4b9e32

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

javascript/2652-sum-multiples.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var sumOfMultiples = function (n) {
6+
let arr = []; // initilialize an empty array
7+
for (let i = 1; i <= n; i++) { // loop through the 1 to n
8+
if ((i % 3 === 0) || (i % 5 === 0) || (i % 7 === 0)) { // if i is divisible by 3 or 5 or 7 then push i into arr
9+
arr.push(i);
10+
}
11+
}
12+
let result = arr.reduce((a, b) => a + b, 0); // find sum of all element of arr and store into result
13+
return result; // return the result
14+
};

0 commit comments

Comments
 (0)