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}
1//#Source https://bit.ly/2neWfJ2
2const isPrime = num => {
3 const boundary = Math.floor(Math.sqrt(num));
4 for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
5 return num >= 2;
6};
7
8console.log(isPrime(11));
9console.log(isPrime(17));
10console.log(isPrime(8));
11
12