fueanta

Is Prime?

Jun 22nd, 2021
819
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const isPrime = (num: number): boolean => {
  2.     if (num <= 1) return false;
  3.     if (num > 2 && num % 2 === 0) return false;
  4.  
  5.     const sqrt = ~~Math.sqrt(num);
  6.  
  7.     for (let i = 3; i <= sqrt; i += 2)
  8.         if (num % i === 0)
  9.             return false;
  10.  
  11.     return true;
  12. }
RAW Paste Data