Spocoman

02. Prime Number Checker

Jan 19th, 2022 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(num) {
  2.     let isPrime = "true";
  3.     if (num < 2){
  4.         isPrime = "false";
  5.     }
  6.     for (let i = 2; i * i <= num; i++) {
  7.         if (num % i === 0)
  8.             isPrime = "false";
  9.     }
  10.     console.log(isPrime);
  11. }
  12.  
  13.  
  14. Тарикатско решение:)
  15.  
  16. function solve(num) {
  17.  
  18.     console.log(num === 3 || num === 5 || num === 7 || num % 2 !== 0 && num % 3 !== 0 && num % 5 !== 0 && num % 7 !== 0);
  19.  
  20. }
  21.  
  22.  
Add Comment
Please, Sign In to add comment