Created
March 19, 2019 15:41
-
-
Save marsgpl/26b5de0529c5f62cc96c0435b9772e80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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