Here you can find the source of max2d( si, ei, sj, ej, calc_maxm, update_array )
Array.prototype.max2d = function ( si, ei, sj, ej, calc_maxm, update_array ) { var maxm = 0.0; for ( var ip = si; ip <= ei; ip++ ) { for ( iq = sj; iq <= ej; iq++ ) { if ( calc_maxm ) { this[ip][iq] = calc_maxm.call(this,this[ip][iq]); }//from ww w . java 2 s.c o m //this[ip][iq] = Math.log10( pic[ip][iq] + 1.0 ); if ( this[ip][iq] > maxm ) { maxm = this[ip][iq]; } } } if ( update_array ) { for ( var i = si; i <= ei; i++) { var na = []; var ca = this[i]; for (var j = sj; j <= ej; j++ ) { na[j] = update_array.call(this, maxm, ca[j]); //ca[j] / maxm; } this[i] = na; } } }
Array.prototype.matrix = function (rows, cols, initial) { var arr = []; for (var i = 0; i < rows; i++) { var columns = []; for (var j = 0; j < cols; j++) { columns[j] = initial; arr[i] = columns; return arr; var matrix = [].matrix(3, 3, 10); console.log(matrix); arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; result = arr.reduceRight(function reduce(sum, value) { return "" + sum + value; }); console.log(result);
Array.prototype.maxChildren = function(childrenPos) { if (childrenPos.length == 1) { return childrenPos[0]; if (this[childrenPos[0]] >= this[childrenPos[1]]) { return childrenPos[0]; } else { return childrenPos[1];