function to find prime numbers in array javascript code example
Example 1: javascript find a prime number
// This seems to be the most common and comprehensive means
// of implementing a 'is a number a prime function' in javascript
// if you would like t0 learn more complex , but efficient algorithms.
// Visit the link below
// https://stackoverflow.com/questions/11966520/how-to-find-prime-numbers-between-0-100
function isPrime(num) {
if(num < 2) return false;
for (let k = 2; k < num; k++){
if( num % k == 0){
return false;
}
}
return true;
}
Example 2: array prime numbers
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]