Skip to content

Instantly share code, notes, and snippets.

@rizesky
Created July 10, 2019 04:24
Show Gist options
  • Save rizesky/50266628eef0e6be1dd8f212ecbc9c4b to your computer and use it in GitHub Desktop.
Save rizesky/50266628eef0e6be1dd8f212ecbc9c4b to your computer and use it in GitHub Desktop.
Get list of Prime Number over specified range
// Function to get list of prime numbers over the specified range
// Return type : Array
function getPrimeNumberList(n) {
//store 2,3 as base value of prime numbers
var primeNumberList = [2, 3];
for (var i = 5; i <= n; i += 2) {
if (primeNumberList.every(function(p) { return i % p; })) {
primeNumberList.push(i);
}
}
return primeNumberList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment