Add sive.js

This commit is contained in:
The Ghost of FOSS' Past 2024-10-21 21:21:04 +00:00
parent a608e6b8d8
commit ad761b8b62

31
sive.js Normal file
View 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()
})