create isPrime()
2022年5月1日小于 1 分钟
isPrime()
create Question
A Prime number is a natural number greater than 1 that is divisible only by itself and 1, such as 2,3,5....
You are asked to implement isPrime()
to check if a number is prime.
Follow-up
What is the time cost of your implementation ? can you improve your approach to have the fewest comparisons?
Code
/**
* @param {number} num - positive integer
*/
function isPrime(num) {
// your code here
}