From 3edefcef5d9502e10b7f4bbd0fdb0fff59e0952c Mon Sep 17 00:00:00 2001 From: sneedgroup-holder Date: Mon, 21 Oct 2024 22:08:35 +0000 Subject: [PATCH] Add libsive.js --- libsive.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 libsive.js diff --git a/libsive.js b/libsive.js new file mode 100644 index 0000000..00daeff --- /dev/null +++ b/libsive.js @@ -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 (var i = 1; i < siveTo; i++) { + if (isPrime(i)) { + primes.push(i) + } + } + + if (isPrime(siveTo)) { + primes.push(siveTo) + } + + return primes +} \ No newline at end of file