Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Created August 4, 2019 10:55
Show Gist options
  • Save yasaryousuf/067b34e2b86d4126de826db71eb4e1e5 to your computer and use it in GitHub Desktop.
Save yasaryousuf/067b34e2b86d4126de826db71eb4e1e5 to your computer and use it in GitHub Desktop.
const isPrime = num => {
let sqrt = Math.sqrt(num);
for(let i = 2; i <= sqrt; i++) {
if(num % i === 0){
return false;
}
}
return true;
}
console.log(isPrime(5));
@yukulele
Copy link

yukulele commented Jul 5, 2022

if (num < 2) return false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment