Skip to content

Instantly share code, notes, and snippets.

@lfborjas
Forked from syntacticsugar/gist:5059926
Last active December 14, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lfborjas/5059955 to your computer and use it in GitHub Desktop.
Save lfborjas/5059955 to your computer and use it in GitHub Desktop.
//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)
);
//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