quick-primefactors
Compute a number's prime factors as quickly as possible, using a cached Sieve of Eratosthenes. This is especially helpful to lookup many numbers' factors one after another.
Install
$ npm install quick-primefactors
var pf = ;
Usage
// Simple examplesconsole; // [47]console; // [2, 2, 2, 2, 3]console; // [3, 17]console; // [2, 2, 5, 5] // More challenging examplesconsole; // [2, 2, 2, 2, 2, 2, 3, 5, 5, 5, 5, 5, 5] // took less than 0.5 seconds console; // [2, 2, 2, 5, 5, 5, 29, 103] // took less than 0.0005 seconds
This module uses a cached Sieve of Eratosthenes for constant time lookup. A new one will be automatically generated if the number you're testing is larger than the currently cached sieve's upper bound.
For best results, lookup your highest number first. This will ensure the sieve is only calculated a single time.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
To test code coverage:
$ npm run cover