Skip to content

Instantly share code, notes, and snippets.

@stevenferrer
Forked from platypusrex/optimusPrime.js
Created June 20, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenferrer/ae50c8a95dbd1321d87569dc729cb5d8 to your computer and use it in GitHub Desktop.
Save stevenferrer/ae50c8a95dbd1321d87569dc729cb5d8 to your computer and use it in GitHub Desktop.
Javascript - Sum all prime numbers
function sumPrimes(num) {
return Array.apply(0, Array(num + 1))
.map(function(x, y){
return y
}).filter(function (i){
return (i > 1) && Array
.apply(0, Array(1 + ~~Math.sqrt(i)))
.every(function(x, y){
return (y < 2) || (i % y !== 0)
});
}).reduce(function(current, previous){
return current + previous;
});
}
sumPrimes(977);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment