我想将坐标(,)映射到特定的订单ID,这将帮助我跟踪坐标更改的时间。
我需要一个公式,它可以根据坐标得到一个特定的ID。
以下是坐标的几个示例:
00-1
10-2
01-3
11-4
02-5
12-6
03-7
13-8
04-9
14-10
05-11
15-12我可以使用这些值的map,但不确定这个值可以增长到多大。
传递坐标时,无法识别要获取订单的公式。
有人能认出这里的逻辑吗..
谢谢
发布于 2019-12-03 22:27:46
以下是两个方向的函数:
const toId = (x, y) => 1 + x + 2*y;
const toCoord = (id) => [--id % 2, id >> 1];
// Demo:
for (let id = 1; id < 16; id++) {
let [x, y] = toCoord(id);
let id2 = toId(x, y);
console.log(id + " to coordinates: [" + x + "," + y + "] ...and back to id: " + id2);
}
https://stackoverflow.com/questions/59155065
复制相似问题