Skip to content

Instantly share code, notes, and snippets.

@sebastianherman
Created January 10, 2021 15:21
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 sebastianherman/abe93c48318dcc48bb97724b49673347 to your computer and use it in GitHub Desktop.
Save sebastianherman/abe93c48318dcc48bb97724b49673347 to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Sum All Primes - freeCodeCamp solution
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