From 3345581eee4a37702f36a785c3e1a2fbfc5ecb14 Mon Sep 17 00:00:00 2001 From: sneedgroup-holder Date: Mon, 21 Oct 2024 22:14:38 +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..532d9ea --- /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 (let 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