Sha256: 673b1f38752bcb76330d20955339cd7f0208beb3ebb389ca6fe02a8c253fc13b
Contents?: true
Size: 578 Bytes
Versions: 30
Compression:
Stored size: 578 Bytes
Contents
function newArrayWithRange(first, last) { let i; const array = []; for ( i = first; i <= last; i++ ) { array.push(i); } return array; } function indivisibleBy(value) { return value % this !== 0; } function sieve(n) { let prime, possibilities; const primes = []; possibilities = newArrayWithRange(2, n); do { prime = possibilities.shift(); primes.push(prime); possibilities = possibilities.filter( indivisibleBy, prime ); } while (possibilities.length > 0); return primes; } export default function (n) { this.primes = sieve(n); }
Version data entries
30 entries across 30 versions & 1 rubygems