Skip to content

Instantly share code, notes, and snippets.

@tlevine
Forked from lfborjas/fun.js
Created March 1, 2013 03:20
Show Gist options
  • Save tlevine/5062245 to your computer and use it in GitHub Desktop.
Save tlevine/5062245 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