1.0.3 • Published 7 years ago

ready-primes v1.0.3

Weekly downloads
17
License
MIT
Repository
github
Last release
7 years ago

ReadyPrimes (Standard)

Pre-calculated collections of prime numbers, natural numbers with distinguished primes and methods to retrieve them.

Get any number of Primes in milliseconds !!!

Standard version is limited to 78,498 primes and 1,000,000 integers. If you need more get ReadyPrimes Extended.


Install

ReadyPrimes will generate necessary files post install.

npm install ready-primes

Usage

const ReadyPrimes = require('ready-primes').ReadyPrimes;

ReadyPrimes.primes(4).then( (result) => {
    console.log(result);
    // output: [ 2, 3, 5, 7 ]
});

ReadyPrimes.integers(7).then( (result) => {
    console.log(result);
    // output: [ 0, 0, 1, 1, 0, 1, 0, 1 ]
});

ReadyPrimes.isPrime(11).then( (result) => {
    console.log(result);
    // output: true
});

Methods

primes ( size, index? )

size: int - length of desired result array
index: int (optional) - start position. Default is 0
returns: Promise < int[] >

ReadyPrimes.primes(4).then( (result) => {
    console.log(result);
    // output: [ 2, 3, 5, 7 ]
});

ReadyPrimes.primes(4, 2).then( (result) => {
    console.log(result);
    // output: [ 5, 7, 11, 13 ]
});

integers ( size, index? )

size: int - the length of desired result array
index: int (optional) - start position. Default is 0
returns: Promise < int[] >

The result is an Array of 1's and 0's, where the index inside the Array determines the actual integer. The length of the result is always size + 1, since Array indexes start from 0.

Example: Array11 = 1, because it is a prime
Array12 = 0, because it is not a prime

ReadyPrimes.integers(7).then( (result) => {
    console.log(result);
    // output: [ 0, 0, 1, 1, 0, 1, 0, 1 ]
});

ReadyPrimes.integers(7, 2).then( (result) => {
    console.log(result);
    // output: [ 1, 1, 0, 1, 0, 1, 0, 1 ]
});

isPrime ( n )

n: int - number to look-up
returns: Promise < boolean >

ReadyPrimes.isPrime(11).then( (result) => {
    console.log(result);
    // output: true
});
1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.9.9

7 years ago

0.9.8

7 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago