Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

return the next higher prime number javascript

function myFunction( a ) {
  function isPrime(num) {
    for (let i = 2; i <= Math.sqrt(num); i++) {
      if (num % i === 0) return false;
    }
    return num > 1;
  }
 let n = a;
 while (!isPrime(n)) n++;
return n
}
Source by upokary.com #
 
PREVIOUS NEXT
Tagged: #return #higher #prime #number #javascript
ADD COMMENT
Topic
Name
5+7 =