Javascript Array d2(rows,columns,fn)
Array.prototype.d2 = function(rows,columns,fn) { var result = new Array(rows); for(var r=0;r<rows;r++) { result[r] = new Array(columns); for(c=0;c<columns;c++) { result[r][c] = fn(r,c);/*from w w w . j a v a 2 s . c o m*/ } } return result; }; function createMatrix(rows,columns){ var matrix = new Array(rows); var m = 0; for(var r=0;r<rows;r++) { matrix[r] = new Array(columns); for(var c=0;c<columns;c++) { matrix[r][c] = m%2; m++; } } return matrix; } createMatrix(10,10).forEach(function(v){aptana.log(v);}); aptana.log(" "); [].d2(10,10,function(r,c){return c%2;}).forEach(function(v){aptana.log(v);});