-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b06180
commit 0d7ba5a
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// https://www.codewars.com/kata/multiples-of-3-or-5 | ||
|
||
// Description: | ||
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | ||
// Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. | ||
// Note: If the number is a multiple of both 3 and 5, only count it once. | ||
|
||
function solution(number){ | ||
let sum = 0; | ||
|
||
for (let currentNum = 0; currentNum < number; currentNum++) { | ||
const multipleOf3 = currentNum % 3 === 0; | ||
const multipleOf5 = currentNum % 5 === 0; | ||
|
||
sum = multipleOf3 || multipleOf5 ? (currentNum + sum) : sum; | ||
} | ||
return sum; | ||
} |