Sha256: 1cca86eec99506aad64612b48e0fcab61ad4003b37b9c9e84bb3fd6016cfd9e4

Contents?: true

Size: 948 Bytes

Versions: 72

Compression:

Stored size: 948 Bytes

Contents

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

	array function rows( input ) {
		// Offset from ASCII code for "A"
		var numChars = asc( input.uCase() ) - 64;
		var width = ( numChars * 2 ) - 1;
		var overTheHill = false;
		var result = [];
		
		// Loop from 1 up to last char and back again
		for( var i=1; i>0; ( overTheHill ? i-- : i++ ) ) {
			
			// First and last rows
			if( i == 1 ) {
				var sidePadding = repeatString( ' ', ( width - i ) / 2 );
				result.append( sidePadding & chr( 64 + i ) & sidePadding );
			// All other rows
			} else {
				var sidePadding = repeatString( ' ', ( ( width - 1 ) / 2 ) - (i-1) );
				var interiorPadding = repeatString( ' ', ( 2 * ( i - 2 ) ) + 1 );
				result.append( sidePadding & chr( 64 + i ) & interiorPadding  & chr( 64 + i ) & sidePadding );
			}
			
			// Toggle the loop in reverse
			if( i >= numChars ) {
				overTheHill = true;
			}
		}
		return result;
	}
			
}

Version data entries

72 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.64 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.63 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.62 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.61 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.60 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.59 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.58 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.57 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.56 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.55 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.54 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.53 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.52 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.51 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.50 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.49 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.48 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.47 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.46 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.45 tracks/cfml/exercises/diamond/Solution.cfc