Currently putting together a function in my app and was wondering if theres a neater way to write this with ES6 rather than use two for loops.
The aim is create a multi-dimensional array to track co-ordinates x & y. This works fine as it stands but I'm hoping to make it neater.
function setBoard() {
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;
}
Appreciate any help!
Thanks
emptyLoc.x = emptyLoc.y = 0;
- those are always the same?