Created
January 10, 2021 15:21
-
-
Save sebastianherman/abe93c48318dcc48bb97724b49673347 to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Sum All Primes - freeCodeCamp solution
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) { | |
let sum = 0; | |
const isPrime = n => ![...Array(n).keys()].slice(2).map(i => !(n%i)).includes(true) && ![0,1].includes(n) | |
for (let i=0; i<=num; i++) { | |
if (isPrime(i)) { | |
sum += i; | |
} | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment