1// This seems to be the most common and comprehensive means
2// of implementing a 'is a number a prime function' in javascript
3// if you would like t0 learn more complex , but efficient algorithms.
4// Visit the link below
5// https://stackoverflow.com/questions/11966520/how-to-find-prime-numbers-between-0-100
6
7function isPrime(num) {
8 if(num < 2) return false;
9
10 for (let k = 2; k < num; k++){
11 if( num % k == 0){
12 return false;
13 }
14 }
15 return true;
16}
1function isPrime(num) {
2 for (let i = 2; i * i <= num; i++)
3 if (num % i === 0)
4 return false;
5 return num > 1;
6}