JavaScript заполняет 2D массив
const r = 4;
const c= 3;
const a = new Array(r).fill(new Array(c).fill(-1));
Doubtful Dog
const r = 4;
const c= 3;
const a = new Array(r).fill(new Array(c).fill(-1));
const fillSquareMatrix = (size) => {
return Array(size)
.fill()
.map((u,y) => Array(size)
.fill()
.map((u,x) => y * size + x + 1));
};
console.log(fillSquareMatrix(3));