-
-
Save bouyagas/02129dbd22d22b35c1130c29d6057e88 to your computer and use it in GitHub Desktop.
JavaScript Prime number with recursion
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 isPrime(n, hn) { | |
if (hn === 0 || n === 1) { | |
return true; | |
} | |
hn = hn || parseInt(n / 2); | |
if (n % hn === 0 && hn !== 1) { | |
return false; | |
} else { | |
return isPrime(n, hn - 1); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment