I have a grid like shown above, and I want to get the cell x and y coordinates with its number.
For example: cell number 18 => x = 3, y = 4
What I've already got:
const grid = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]
]
const width = grid[0].length //As my grid will always be regular, I just pick the first row's length
const height = grid.length
console.log(getXYCoords(8, grid))
function getXYCoords(cell, grid) {
//This is where I can't figure out how to do it
}