Answers for "find prime number function javascript es6"

8

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;
}
Posted by: Guest on May-20-2020
0

find prime number function javascript es6

//#Source https://bit.ly/2neWfJ2 
const isPrime = num => {
  const boundary = Math.floor(Math.sqrt(num));
  for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
  return num >= 2;
};

console.log(isPrime(11));
console.log(isPrime(17));
console.log(isPrime(8));
Posted by: Guest on September-06-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language