lib/rotateMatrix.js
function transpose(matrix) {
	// For NxN matrix
	var n = matrix[0].length;
	var temp;

	// Walk through columns
	for (var i = 0, j = 0; i < n; i++) {
		j = i;
		// Walk through rows
		while (j < n) {
			if (i !== j) {
				temp = matrix[i][j];
				matrix[i][j] = matrix[j][i];
				matrix[j][i] = temp;
			}
			j++;
		}
	}
}
function transpose(matrix) {
	// For NxN matrix
	var n = matrix[0].length;
	var temp;

	// Walk through columns
	for (var i = 0, j = 0; i < n; i++) {
		j = i;
		// Walk through rows
		while (j < n) {
			if (i !== j) {
				temp = matrix[i][j];
				matrix[i][j] = matrix[j][i];
				matrix[j][i] = temp;
			}
			j++;
		}
	}
}
function transpose ( matrix ) { // For NxN matrix var n = matrix [ 0 ] . length ; var temp ; // Walk through columns for ( var i = 0 , j = 0 ; i < n ; i ++ ) { j = i ; // Walk through rows while ( j < n ) { if ( i !== j ) { temp = matrix [ i ] [ j ] ; matrix [ i ] [ j ] = matrix [ j ] [ i ] ; matrix [ j ] [ i ] = temp ; } j ++ ; } } }
Transpose a 2D matrix
Transpose a 2D matrix