Sha256: e689b0b31db81fab6d74c691207f3c6300a488a82522b651a4463091d2287b64

Contents?: true

Size: 950 Bytes

Versions: 74

Compression:

Stored size: 950 Bytes

Contents

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

	array function rows( letter ) {
		// Offset from ASCII code for "A"
		var numChars = asc( letter.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

74 entries across 74 versions & 1 rubygems

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