Advertisement
dabidabidesh

Prime Number Checker

May 25th, 2020
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //02.Prime Number Checker
  2. function primeNumberChecker(numb) {
  3.   'use strict'
  4.   let count = 0
  5.   for (let i = 1; i <= numb; i++)
  6.     if (numb % i === 0)
  7.       count++
  8.   console.log(count === 2 ? true : false)
  9. }
  10. primeNumberChecker1(1)
  11.  
  12. function primeNumberChecker0(numb) {
  13.   'use strict'
  14.   const isPrime0 = num => {
  15.     for (let i = 2, s = Math.sqrt(num); i <= s; i++)
  16.       if (num % i === 0) return false
  17.     return num > 1
  18.   }
  19.   console.log(isPrime0(numb))
  20. }
  21.  
  22. function primeNumberChecker1(numb) {
  23.   'use strict'
  24.  
  25.   const isPrime = num => {
  26.     for (let i = 2; i < num; i++)
  27.       if (num % i === 0) return false;
  28.     return num > 1;
  29.   }
  30.   console.log(isPrime(numb))
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement