Created
June 26, 2018 22:45
-
-
Save davidsa/20a3d703b52662131c5b7c6bdc3da0e2 to your computer and use it in GitHub Desktop.
first 0..100 Prime numbers recursively
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 isPrimeNumberRecursive(n, next) { | |
if (n <= 1) { | |
return false | |
} | |
if (!next) { | |
next = n - 1 | |
} | |
if (next === 1) { | |
return true | |
} | |
if (n % next === 0) { | |
return false | |
} | |
return isPrimeNumberRecursive(n, next - 1) | |
} | |
const numbers = [...Array(100).keys()] | |
numbers.forEach(n => { | |
const result = isPrimeNumberRecursive(n) | |
result && console.log(n) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment