【发布时间】:2020-10-17 10:04:54
【问题描述】:
我有一个如上所示的网格,我想获取单元格 x 和 y 坐标及其编号。
例如:单元格编号 18 => x = 3, y = 4
我已经得到了什么:
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
}
【问题讨论】:
标签: javascript