thaw-sieve-of-eratosthenes
Version:
The Sieve of Eratosthenes (an ancient Greek prime number generator) as a JavaScript library
37 lines (27 loc) • 1.85 kB
Markdown
# thaw-sieve-of-eratosthenes
A JavaScript implementation of the Sieve of Eratosthenes, an ancient Greek prime number generator.
[](https://travis-ci.org/tom-weatherhead/thaw-sieve-of-eratosthenes)
[](https://www.npmjs.com/package/thaw-sieve-of-eratosthenes)
[](https://www.npmjs.com/package/thaw-sieve-of-eratosthenes)
[](https://github.com/tom-weatherhead/thaw-sieve-of-eratosthenes/blob/master/LICENSE)
[](https://codeclimate.com/github/tom-weatherhead/thaw-sieve-of-eratosthenes/maintainability)
[](https://snyk.io/test/github/tom-weatherhead/thaw-sieve-of-eratosthenes?targetFile=package.json&package-lock.json)
Most of this project's infrastructure was stolen from Jason Mulligan's ([avoidwork](https://github.com/avoidwork)'s) [tiny-graph](http://avoidwork.github.io/tiny-graph) project.
## Installation
To install the stable version:
```
npm install --save thaw-sieve-of-eratosthenes
```
## Example
```js
const engine = require('thaw-sieve-of-eratosthenes');
console.log(engine.sieve(20)); // [2, 3, 5, 7, 11, 13, 17, 19]
console.log(engine.factorize(72)); // [2, 2, 2, 3, 3]
```
## API
#### factorize(n)
Returns the unique prime factorization of `n` as a list of integers
#### sieve(n)
Returns the list of all prime numbers less than `n`
## License
[MIT](https://choosealicense.com/licenses/mit/)