Skip to content

Instantly share code, notes, and snippets.

@marsgpl
Created March 19, 2019 15:41
Show Gist options
  • Save marsgpl/26b5de0529c5f62cc96c0435b9772e80 to your computer and use it in GitHub Desktop.
Save marsgpl/26b5de0529c5f62cc96c0435b9772e80 to your computer and use it in GitHub Desktop.
const getPrimes = function(n) {
const result = []
for ( let i=2;i<=n;++i ) {
if ( getPrimes.isPrime(i) ) {
result.push(i)
}
}
return result
}
getPrimes.isPrime = function(n) {
if ( n < 2 ) { return false }
for ( let i=2; i<n; ++i ) {
if ( n%i == 0 ) {
return false
}
}
return true
}
console.log(getPrimes(1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment