0.0.1 • Published 9 months ago

@santi100/eratosthenes-sieve v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Santi's Energetic Sieve of Eratosthenes

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 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 number n.

    NameTypeDescriptionOptional?Default
    nnumberThe upper limit of the range of numbers to check for primes.NoN/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.