Sha256: 07a4a73f0ec44a53f021181c53b5d5a750bc5b8efc4760d26200b1c25d8099f8

Contents?: true

Size: 734 Bytes

Versions: 396

Compression:

Stored size: 734 Bytes

Contents

module.exports = class Prime
  @nth: (nthPrime) ->
    throw "Prime is not possible" if nthPrime == 0
    @generatePrimes(200000)
    @realPrimes[nthPrime - 1]

  @generatePrimes: (uptoNumber) ->
    return @realPrimes if @realPrimes

    possiblePrimes = []

    for numberValue in [2..uptoNumber]
      possiblePrimes.push({ number: numberValue, prime: true })

    for number in [2..Math.sqrt(possiblePrimes.length)]
      for currentPrime in possiblePrimes
        if currentPrime.number != number && currentPrime.number % number == 0
          currentPrime.prime = false

    primeCount = 0

    @realPrimes = possiblePrimes.filter (possiblePrime) -> possiblePrime.prime
    @realPrimes = @realPrimes.map (prime) -> prime.number

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.179 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.178 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.177 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.176 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.175 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.174 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.173 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.172 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.171 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.170 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.169 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.167 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.166 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.165 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.164 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.163 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.162 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.161 tracks/coffeescript/exercises/nth-prime/example.coffee
trackler-2.2.1.160 tracks/coffeescript/exercises/nth-prime/example.coffee