prime-number
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

prime-number

check if a number is prime

Is it 1 a prime? Some years ago I created a djembe rhythm generated by prime numbers, and it sounds good if 1 is considered prime. However, the algorithm implemented here defines 1 as a not prime.

Installation

With npm do

npm install prime-number

Usage

As you might expect, you can simply do

import isPrime from 'prime-number'

console.log(isPrime(19)) // true

You can also use CommonJS.

const isPrime = require('prime-number')

Benchmarks

Clone this repo and install packages for benchmarks with --no-save flag.

npm install check-prime is-prime --no-save

Then run benchmark scripts.

Using this prime-number package.

npm run benchmark:prime-number
Found 8363 primes
Primality benchmark: 7.064ms

Using is-prime package.

npm run benchmark:is-prime
Found 8363 primes
Primality benchmark: 7.045ms

Using check-prime package.

npm run benchmark:check-prime
Found 8363 primes
Primality benchmark: 23.785ms

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.011latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.011
1.0.28
1.0.11
1.0.00
0.2.239
0.2.10
0.2.01
0.1.20
0.1.10
0.1.01

Package Sidebar

Install

npm i prime-number

Weekly Downloads

61

Version

2.0.0

License

MIT

Unpacked Size

4.02 kB

Total Files

5

Last publish

Collaborators

  • fibo