Write the test cases on prime number with result ?

  • Let the prime number be n.
  • Divide the number n by 1 remainder=0 pass.
  • Divide the number n by n remainder=0 pass.
  • Divide the number n by 2 remainder!=0 pass.
  • Divide the number n by up to n-1 and if remainder not equal zero, then it is a prime number.
 Prime Number Algorithm

Prime Number Algorithm

Example

function primeTester (n) {
//take out edge case 0 and 1
if(n<=1)
return false;

//go from 3 since 2 is a prime number
for(var i=3; i<n; i++){
//check if n is divisible by i
if(n%i ===0 )
return false
}

//if passed all out test
return true;
}

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,