Sha256: bd66f174487339bea8ec78309e4affba3adc79f487bdced60b413e215137b75e

Contents?: true

Size: 1.16 KB

Versions: 72

Compression:

Stored size: 1.16 KB

Contents

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

	function saddlePoints( input ) {
		if( input.isEmpty() || input[ 1 ].isEmpty() ) {
			return [];
		}
		
		var result = [];
		// Loop over each column
		for( var col=1; col<=3; col++ ) {
			
			// Loop over each row
			for( var row=1; row<=3; row++ ) {
				
				// This value must be the biggest int he row
				if( getAt( input, row, col ) >= rowMax( input, row )
					// and the least in the column
					&& getAt( input, row, col ) <= colMin( input, col ) ){
					
					// Silly exercise uses inferior 0-based numbering!
					result.append( {
						row : row-1,
						column : col-1
					} );
					
				} // End check
				
			} // end row loop
			
		} // end col loop
		
		return result;
	}
	
	/**
	* Get minimum value for a column
	*/
	private function colMin( input, col ) {
		return [ input[ 1 ][ col ], input[ 2 ][ col ], input[ 3 ][ col ] ].min();
	}	
	
	/**
	* Get maximum value for a row
	*/
	private function rowMax( input, row ) {
		return input[ row ].max();
	}	
	
	/**
	* Get a specific value from the matrix
	*/
	private function getAt( input, row, col ) {
		return input[ row ][ col ];
	}
		
}

Version data entries

72 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.104 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.103 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.102 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.101 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.100 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.99 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.98 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.97 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.96 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.95 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.94 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.93 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.92 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.91 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.90 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.89 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.88 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.87 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.86 tracks/cfml/exercises/saddle-points/Solution.cfc
trackler-2.2.1.85 tracks/cfml/exercises/saddle-points/Solution.cfc