UNPKG

prime-number

Version:
69 lines (45 loc) 1.28 kB
# prime-number > check if a number is prime [Is it 1 a prime?](https://en.wikipedia.org/wiki/Prime_number#Primality_of_one) 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](https://npmjs.org/) do ```bash npm install prime-number ``` ## Usage As you might expect, you can simply do ```js import isPrime from 'prime-number' console.log(isPrime(19)) // true ``` You can also use CommonJS. ```js const isPrime = require('prime-number') ``` ## Benchmarks Clone this repo and install packages for benchmarks with `--no-save` flag. ```sh npm install check-prime is-prime --no-save ``` Then run benchmark scripts. Using this `prime-number` package. ```sh npm run benchmark:prime-number Found 8363 primes Primality benchmark: 7.064ms ``` Using [is-prime](https://www.npmjs.com/package/is-prime) package. ```sh npm run benchmark:is-prime Found 8363 primes Primality benchmark: 7.045ms ``` Using [check-prime](https://www.npmjs.com/package/check-prime) package. ```sh npm run benchmark:check-prime Found 8363 primes Primality benchmark: 23.785ms ``` ## License [MIT](https://fibo.github.io/mit-license/)