Skip to content

Instantly share code, notes, and snippets.

@OdearOgy
Last active November 4, 2018 18:09
Show Gist options
  • Select an option

  • Save OdearOgy/3d791d9426cd18cf58eb5eaf58927a81 to your computer and use it in GitHub Desktop.

Select an option

Save OdearOgy/3d791d9426cd18cf58eb5eaf58927a81 to your computer and use it in GitHub Desktop.
this code logs sum of the prime nums in the given range
const reducer = (accumulator, currentValue) => accumulator + currentValue;
function somOfPrimes(range) {
let store = [];
let primes = [];
for (let i = 2; i <= max; ++i) {
if (!store [i]) {
primes.push(i);
for (let j = i << 1; j <= max; j += i) {
store[j] = true;
}
}
}
return primes.reduce(reducer);
}
console.log(sumOfPrimes(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment