Sha256: 44757196e1679505def5a100ac579c769b7d5d9fe93aa641ef9cc0741f0224af
Contents?: true
Size: 553 Bytes
Versions: 72
Compression:
Stored size: 553 Bytes
Contents
/** * Here is an example solution for the NthPrime exercise */ component { function prime( input ) { if( input == 0 ) { return false; } var primes = []; var candidate = 1; while( primes.len() < input ) { candidate ++; if( candidate % 2 == 0 && candidate != 2 ) { continue; } var factor = 1; var isPrime = true; while( ++factor < candidate ) { if( candidate % factor == 0 ) { isPrime = false; break; } } if( isPrime ) { primes.append( candidate ); } } return primes.last(); } }
Version data entries
72 entries across 71 versions & 1 rubygems