-
-
Save tlevine/5062245 to your computer and use it in GitHub Desktop.
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
//The fun solution: using array methods | |
var ary = []; | |
for(var i = 1; i <= 1000; i++){ ary.push(i); } | |
console.log( | |
ary.filter(function(item){ | |
return (item % 3 == 0 || item % 5 == 0) | |
}).reduce(function(memo, current){ | |
return memo + current | |
}, 0) | |
); |
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
//The obvious solution: no array magic stuff | |
console.log((function the_sum(min, max){ | |
var sum = 0; | |
for(var i= min; i <= max; i++){ | |
if(i % 5 == 0 || i % 3 == 0){ | |
sum += i | |
} | |
} | |
return sum | |
})(1,1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment