Created
October 15, 2015 04:18
-
-
Save platypusrex/3010bd4b7c95ec447662 to your computer and use it in GitHub Desktop.
Javascript - Sum all prime numbers
This file contains hidden or 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
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