Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Check if given number is prime
const isPrime = number => {
if (number < 2) return false;
// Divide number by all numbers from 2 to sqrt(number)
// If divisible, then its not a prime
let div;
for (div = 2; div <= Math.sqrt(number); div++)
if (number % div == 0)
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment