Skip to content

Commit 9c9fc1a

Browse files
committed
added isPrime function
1 parent d04bbba commit 9c9fc1a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// isPrime.js
2+
function isPrime(num) {
3+
// If the number is less than 2, it is not prime
4+
if (num < 2) {
5+
return false;
6+
}
7+
8+
// Check if the number has divisors (excluding 1 and itself)
9+
for (let i = 2; i <= Math.sqrt(num); i++) {
10+
if (num % i === 0) {
11+
return false; // If a divisor is found, it is not prime
12+
}
13+
}
14+
15+
return true; // If no divisors are found, the number is prime
16+
}
17+
18+
19+
console.log("All test cases executed!");

0 commit comments

Comments
 (0)