Last active
December 27, 2015 19:18
-
-
Save mmloveaa/0566fc5d62836ab454d6 to your computer and use it in GitHub Desktop.
Multiples of 3 and 5
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
// 12/22/2015 | |
// Multiples of 3 and 5 | |
// 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. | |
// Find the sum of all the multiples of 3 or 5 below 1000. | |
// My Solution: | |
function multisum(num){ | |
var arr1=[]; | |
var total=0; | |
for(var i=0; i<num; i++){ | |
if(i%5==0||i%3==0){ | |
arr1.push(i) | |
} | |
} | |
for(var j=0; j<arr1.length;j++){ | |
total+=arr1[j] | |
} | |
return total; | |
} | |
multisum(15) | |
//3,5,6,9,10,12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment