I have a suspicion that function like below can be written with single loop(maybe not), but can’t figure out, how to achieve that.
//TASK function must return 2-dimensional array,
//representing NxN grid(matrix), with coordinates(indexes) for each element
//WHY? some visualization seems to be helpful when working on
//Project Euler 11 problem
const generateQuadraticTestGrid = (size) => {
let testGrid = [];
for (let i = 0; i < size; i++) {
testGrid.push([])
for (let j = 0; j < size; j++) {
testGrid[i].push(String(i) + ',' + String(j));
}
}
return testGrid;
}
console.log(generateQuadraticTestGrid(6))
/*
Output:
[
[ '0,0', '0,1', '0,2', '0,3', '0,4', '0,5' ],
[ '1,0', '1,1', '1,2', '1,3', '1,4', '1,5' ],
[ '2,0', '2,1', '2,2', '2,3', '2,4', '2,5' ],
[ '3,0', '3,1', '3,2', '3,3', '3,4', '3,5' ],
[ '4,0', '4,1', '4,2', '4,3', '4,4', '4,5' ],
[ '5,0', '5,1', '5,2', '5,3', '5,4', '5,5' ]
]
*/