function for exchanging two rows of a matrix
function swap ( mat , row1 , row2 , col ) { for ( i = 0 ; i < col ; i ++ ) { var temp = mat [ row1 ] [ i ] ; mat [ row1 ] [ i ] = mat [ row2 ] [ i ] ; mat [ row2 ] [ i ] = temp ; } }