Add sive.js
This commit is contained in:
parent
a608e6b8d8
commit
ad761b8b62
1 changed files with 31 additions and 0 deletions
31
sive.js
Normal file
31
sive.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
const readline = require("readline");
|
||||||
|
const { stdin: input, stdout: output } = require('node:process');
|
||||||
|
|
||||||
|
|
||||||
|
let primes = []
|
||||||
|
|
||||||
|
const isPrime = num => {
|
||||||
|
for(let i = 2, s = Math.sqrt(num); i <= s; i++) {
|
||||||
|
if(num % i === 0) return false;
|
||||||
|
}
|
||||||
|
return num > 1;
|
||||||
|
} //the only part taken from stackoverflow lmao...
|
||||||
|
|
||||||
|
const rl = readline.createInterface({ input, output });
|
||||||
|
|
||||||
|
rl.question('Sive to: ', (siveTo) => {
|
||||||
|
siveTo = Number(siveTo)
|
||||||
|
|
||||||
|
|
||||||
|
for (var i = 1; i < siveTo; i++) {
|
||||||
|
if (isPrime(i)) {
|
||||||
|
primes.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
primes.push(siveTo)
|
||||||
|
|
||||||
|
console.table(primes)
|
||||||
|
|
||||||
|
rl.close()
|
||||||
|
})
|
Loading…
Reference in a new issue