Add libsive.js
This commit is contained in:
parent
1ceb558820
commit
3345581eee
1 changed files with 23 additions and 0 deletions
23
libsive.js
Normal file
23
libsive.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const isPrime = (num) => {
|
||||
for (let i = 2, s = Math.sqrt(num); i <= s; i++) {
|
||||
if (num % i === 0) return false;
|
||||
}
|
||||
return num > 1;
|
||||
}
|
||||
|
||||
function sive(siveTo) {
|
||||
let primes = [];
|
||||
siveTo = Number(siveTo);
|
||||
|
||||
for (let i = 1; i < siveTo; i++) {
|
||||
if (isPrime(i)) {
|
||||
primes.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPrime(siveTo)) {
|
||||
primes.push(siveTo);
|
||||
}
|
||||
|
||||
return primes;
|
||||
}
|
Loading…
Reference in a new issue