How do you write a function given arguments width, height and value that make a two dimensional array with that given width and height and fill every spot with a given value?
function createGrid(width, height, value) {
var array = new Array(height);
for (var i = 0; i < height; i++) {
array[i] = new Array(width);
}
for (var j = 0; j < width; j++) {
for (var k = 0; k < height; k++) {
array[k][j] = value;
}
}
return array;
}
This is what I wrote, but I'm wondering why I can't just write something like var array = new array(width, height). Why isn't such simple syntax possible in Javascript?