Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

prime

// code re-use right here
const isPrime = num => {
  for (let i = 2, s = Math.sqrt(num); i <= s; i++)
    if (num % i === 0) return false;
  return num > 1;
}

function closestPrime(num) {
  while (!isPrime(num)) {
    num++
  }
  return num;
}
console.log(closestPrime(38))
console.log(closestPrime(7))

Créé il y a 1 semaine.

Rechercher un Pastebin

Aucun paste trouvé.