Skip to content

Commit

Permalink
Update isPrime.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherny committed Jul 26, 2017
1 parent f9a7058 commit 8a89405
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion coding-easy/isPrime.js
Expand Up @@ -14,7 +14,7 @@ function isPrime(n) {
return false
}
for (let i = 2; i < Math.ceil(Math.sqrt(n)) + 1; i++) {
if (n % i === 0) {
if (n % i === 0 && i !== n) {
return false
}
}
Expand All @@ -27,6 +27,7 @@ import { test } from 'ava'

test(t => t.is(isPrime(0), false))
test(t => t.is(isPrime(1), false))
test(t => t.is(isPrime(2), true))
test(t => t.is(isPrime(9), false))
test(t => t.is(isPrime(17), true))
test(t => t.is(isPrime(25), false))
Expand Down

0 comments on commit 8a89405

Please sign in to comment.