diff options
Diffstat (limited to 'usth/ICT3.2/prac/2/8.js')
-rw-r--r-- | usth/ICT3.2/prac/2/8.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/usth/ICT3.2/prac/2/8.js b/usth/ICT3.2/prac/2/8.js new file mode 100644 index 0000000..07a4042 --- /dev/null +++ b/usth/ICT3.2/prac/2/8.js @@ -0,0 +1,11 @@ +function isPrime(n) { + if (n < 2 || n != Math.trunc(n)) + return false; + for (let i = 2; i * i <= n; ++i) + if (n % i == 0) + return false; + return true; +} + +if (!module.parent) + console.log(isPrime(Number(process.argv[2])) ? 'prime' : 'no prime'); |