ready-primes
Get Primes in milliseconds. Pre-calculated collections of prime numbers, natural numbers with distinguished primes and methods to retrieve them.
Last updated 2 years ago by the_mouse_house .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ready-primes 
SYNC missed versions from official npm registry.

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: Array[11] = 1, because it is a prime
Array[12] = 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
});

Current Tags

  • 1.0.3                                ...           latest (2 years ago)

14 Versions

  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.9.9                                ...           3 years ago
  • 0.9.8                                ...           3 years ago
  • 0.9.7                                ...           3 years ago
  • 0.9.6                                ...           3 years ago
  • 0.9.5                                ...           3 years ago
  • 0.9.4                                ...           3 years ago
  • 0.9.3                                ...           3 years ago
  • 0.9.2                                ...           3 years ago
  • 0.9.1                                ...           3 years ago
  • 0.9.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 14
Dependencies (9)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |