Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

return the next higher prime number javascript

// Write a function that takes a number (a) as argument. If a is prime number, return a. If a is not prime number then return the next higher prime number.

const nextPrimeNumber = (num) => {
    for(let i = 2; i < num ; i++) {
        if(num % i === 0) {
            return nextPrimeNumber(num + 1)
        }

    }
    return num;
};

const input = 90;
console.log(nextPrimeNumber(input)); // 97
Comment

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
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: get the value of css properties js 
Javascript :: multiple transform properties javascript 
Javascript :: javascript delete first character in string 
Javascript :: dayjs timezone 
Javascript :: compare NaN in javascript if condititon 
Javascript :: vue property decorator emit 
Javascript :: jquery disable option by value 
Javascript :: javascript transpose rows to columns 
Javascript :: add variables in javascript 
Javascript :: jquery switch class 
Javascript :: install gulp ubuntu 20.04 
Javascript :: moment get week 
Javascript :: get current date + 1 js 
Javascript :: mongoose schema 
Javascript :: sort array based on another array 
Javascript :: un hover in jquery 
Javascript :: redux logger 
Javascript :: react native flatlist 
Javascript :: how to show bootstrap 5 modal using jquery 
Javascript :: how to copy to clipboard in react js 
Javascript :: jquery replace text in button 
Javascript :: repeat string n times javascript 
Javascript :: Iterate with JavaScript For Loops 
Javascript :: audio in react 
Javascript :: jquery external script 
Javascript :: iterate 0 to n using for loop javascript 
Javascript :: swapping elements in an array 
Javascript :: react native release apk command 
Javascript :: destructure dynamic property 
Javascript :: sass config.json vs code 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =