Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Last active April 28, 2022 18:35
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 MuddyBootsCode/8b99e4a4429dbef4efaaf2ccd31d069e to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/8b99e4a4429dbef4efaaf2ccd31d069e to your computer and use it in GitHub Desktop.
function primeSummation(n) {
let nums = Array.from({length: n - 1}, (_, i) => i + 1)
nums = nums.filter((n) => {
if (n <= 3) { return n > 1; }
if (n % 2 == 0 || n % 3 == 0) { return false; }
for (var i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) { return false; }
}
return true;
})
return nums.reduce((a, b) => a + b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment