Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create 2652-sum-multiples.js
  • Loading branch information
chetannada committed Aug 11, 2023
commit 0b996feb36f1420f7a7e6d2e7df6068d3aae9371
14 changes: 14 additions & 0 deletions javascript/2652-sum-multiples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {number} n
* @return {number}
*/
var sumOfMultiples = function (n) {
let arr = []; // initilialize an empty array
for (let i = 1; i <= n; i++) { // loop through the 1 to n
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
arr.push(i);
}
}
let result = arr.reduce((a, b) => a + b, 0); // find sum of all element of arr and store into result
return result; // return the result
};