Skip to content

Instantly share code, notes, and snippets.

@davidsa
Created June 26, 2018 22:45
Show Gist options
  • Save davidsa/20a3d703b52662131c5b7c6bdc3da0e2 to your computer and use it in GitHub Desktop.
Save davidsa/20a3d703b52662131c5b7c6bdc3da0e2 to your computer and use it in GitHub Desktop.
first 0..100 Prime numbers recursively
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