Skip to content

Instantly share code, notes, and snippets.

@typehorror
Created February 2, 2020 17:54
Show Gist options
  • Save typehorror/0101971952a07e0def37d263e26f20be to your computer and use it in GitHub Desktop.
Save typehorror/0101971952a07e0def37d263e26f20be to your computer and use it in GitHub Desktop.
Simpler solution of the iterative method
function sumMultiples(n, mul){
var sum=0;
for (var i = 0 ; i < n ; i = mul + i) {
sum += i;
}
return sum;
}
console.log(sumMultiples(1000, 5) + sumMultiples(1000, 3) - sumMultiples(1000, 15));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment