<!DOCTYPE html>
<html>
<body>
<script>
document.write(multSilgarth3(99999999));
function multSilgarth1(n) {
var array = [];
var result = 0;
for (var i = 1; i < n; i ++) {
if (i % 3 == 0 || i % 5 == 0) {
array.push(i);
}
}
for (var num of array) {
result += num;
}
return result;
}
function multSilgarth2(n) {
var array = [];
for (var i = 1; i < n; i ++) {
if (i % 3 == 0 || i % 5 == 0) {
array.push(i);
}
}
return array.reduce(function(prev, current) {
return prev + current;
});
}
function multSilgarth3(n) {
var array = [];
while (n >= 1) {
n--;
if (n%3==0||n%5==0) {
array.push(n);
}
}
return array.reduce(function(prev, current) {
return prev + current;
});
}
function multSilgarth4(n) {
var sum = 0;
while (n >= 1) {
n--;
if (n%3==0||n%5==0) {
sum += n;
}
}
return sum;
}
function multSilgarth5(n) {
n = n-1;
var sum = 0;
for (n; n >= 1 ;n--) {
(n%3==0||n%5==0) ? sum += n : null;
}
return sum;
}
function multSilgarth(N) {
var threes = Math.floor(--N / 3);
document.write(threes+ "<br>");
var fives = Math.floor(N / 5);
document.write(fives+ "<br>");
var fifteen = Math.floor(N / 15);
document.write(fifteen + "<br>");
return (3 * threes * (threes + 1) + 5 * fives * (fives + 1) - 15 * fifteen * (fifteen + 1)) / 2;
}
</script>
</body>
</html>
https://github.com/xitu/gold-miner/blob/master/TODO/what-i-learned-from-writing-six-functions-that-all-did-the-same-thing.md