-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathis_a_prime_number.js
More file actions
21 lines (19 loc) · 909 Bytes
/
is_a_prime_number.js
File metadata and controls
21 lines (19 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/******************************************************************************************
* CODEWARS IS A PRIME NUMBER CHALLENGE *
* Problem Statement *
* Define a function that takes an integer argument & returns logical value true or false *
* depending on if the integer is a prime. *
* *
*****************************************************************************************/
function isPrime(num) {
if (num < 2) return false;
if (num === 2) return true;
let isAPrimeNumber = true;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
isAPrimeNumber = false;
break;
}
}
return isAPrimeNumber;
}