I'm in the process of developing a function for my app and I'm curious if there's a more elegant way to implement it using ES6, without relying on two for loops.
The goal is to create a multi-dimensional array that keeps track of x and y coordinates. While the current implementation works effectively, I'm looking for a cleaner solution.
function createBoard() {
boardParts = new Array(tileCount);
for (let i = 0; i < tileCount; ++i) {
boardParts[i] = new Array(tileCount);
for (let j = 0; j < tileCount; ++j) {
boardParts[i][j] = new Object();
boardParts[i][j].x = tileCount - 1 - i;
boardParts[i][j].y = tileCount - 1 - j;
}
}
emptyLoc.x = boardParts[tileCount - 1][tileCount - 1].x;
emptyLoc.y = boardParts[tileCount - 1][tileCount - 1].y;
solved = false;
}
Any suggestions or guidance would be greatly appreciated!
Many thanks