Creación de una matriz 2D en JavaScript
var [r, c] = [5, 5];
var m = Array(r).fill().map(()=>Array(c).fill(0));
Breakable Boar
var [r, c] = [5, 5];
var m = Array(r).fill().map(()=>Array(c).fill(0));
function zeros(dimensions) {
var array = [];
for (var i = 0; i < dimensions[0]; ++i) {
array.push(dimensions.length == 1 ? 0 : zeros(dimensions.slice(1)));
}
return array;
}
> zeros([5, 3]);
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]