Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Last active December 27, 2015 19:18
Show Gist options
  • Save mmloveaa/0566fc5d62836ab454d6 to your computer and use it in GitHub Desktop.
Save mmloveaa/0566fc5d62836ab454d6 to your computer and use it in GitHub Desktop.
Multiples of 3 and 5
// 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