Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active August 29, 2015 14:09
Show Gist options
  • Save gregtatum/229324c6cfd33a792540 to your computer and use it in GitHub Desktop.
Save gregtatum/229324c6cfd33a792540 to your computer and use it in GitHub Desktop.
consoleMatrixElements() - Output multiple console.tables() for an array buffer of matrix elements
var consoleMatrixElements = function( els, decimalPlaces ) {
var i, j, el, results;
results = [];
j = 0;
for( i=0; i < els.length; i++ ) {
if( j === 0 ) {
results.push([]);
}
el = els[i];
if( typeof decimalPlaces === "number" ) {
el = Math.round( Math.pow(10, decimalPlaces) * el ) / Math.pow(10, decimalPlaces);
}
results[Math.floor(i / 4) % 4].push( el );
j++;
j %= 4;
if( i % 16 === 15 ) {
console.table( results );
results = [];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment