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.104 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.103 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.102 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.101 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.100 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.99 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.98 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.97 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.96 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.95 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.94 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.93 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.92 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.91 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.90 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.89 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.88 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.87 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.86 tracks/cfml/exercises/diamond/Solution.cfc
trackler-2.2.1.85 tracks/cfml/exercises/diamond/Solution.cfc