Sha256: 3c05a4ac0a32e634a4b9666a0e01fd4739497ad3ffdb504decc14433a8856122

Contents?: true

Size: 579 Bytes

Versions: 74

Compression:

Stored size: 579 Bytes

Contents

/**
* Here is an example solution for the NthPrime exercise
*/
component {

	function prime( number ) {
		if( number == 0 ) {
			throw( 'there is no zeroth prime' );
		}
		var primes = [];
		var candidate = 1;
		while( primes.len() < number ) {
			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

74 entries across 74 versions & 1 rubygems

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