@santi100/eratosthenes-sieve
v0.0.1
Published
Santi's Energetic Sieve of Eratosthenes: How can you sift numbers?
Downloads
8
Maintainers
Readme
Santi's Energetic Sieve of Eratosthenes
- 🚀 Lightweight and fast
- 👴 ES3-compliant
- 💻 Portable between the browser and Node.js
- 📘 Includes TypeScript definitions
What's this?
This is a simple, lightweight implementation of the Sieve of Eratosthenes
Installation
- Via NPM:
npm install @santi100/eratosthenes-sieve
- Via Yarn:
yarn add @santi100/eratosthenes-sieve
- Via PNPM:
pnpm install @santi100/eratosthenes-sieve
API
function sieve(n: number): number[];
Finds all prime numbers from 2 up to a given numbern
.| Name | Type | Description | Optional? | Default | | ---- | ---- | ----------- | --------- | ------- | |
n
|number
| The upper limit of the range of numbers to check for primes. | No | N/A |
Usage
// Import the sieve function
const sieve = require('@santi100/eratosthenes-sieve'); // CJS
import sieve = require('@santi100/eratosthenes-sieve'); // TypeScript
import sieve from '@santi100/eratosthenes-sieve'; // ESM
// Use the sieve function to find prime numbers up to 100
const primesUpTo100 = sieve(100);
// Print the prime numbers
console.log('Prime numbers up to 100:', primesUpTo100); // outputs [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
Contribute
Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.