Created
May 25, 2018 23:27
-
-
Save rafaelguinho/6d0411616371ecef384c81b673201de5 to your computer and use it in GitHub Desktop.
A generator function that produces prime numbers
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
function *primeNumber(){ | |
let currentNumber = 2; | |
yield currentNumber; | |
while(true){ | |
for(let i = currentNumber; i > 1; i--){ | |
if(currentNumber % i == 0){ | |
currentNumber++; | |
continue; | |
} | |
} | |
if(currentNumber % currentNumber == 0 && currentNumber % 1 == 0) | |
yield currentNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment