var c={ 0:[0], 1:[1,9], 2:[2,10,18], 3:[3,11,19,27], 4:[4,12,20,28,36], 5:[5,13,21,29,37,45], 6:[6,14,22,30,38,46,54], 7:[7,15,23,31,39,47,55,63], 8:[8,16,24,32,40,48,56,64], 9:[17,25,33,41,49,57,65], 10:[26,34,42,50,58,66], 11:[35,43,51,59,67], 12:[44,52,60,68], 12:[53,61,69], 12:[62,70], 12:[71], }
1 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
function gen(num) {
let m = Math.floor(num / 2)
let result = {}
for (let i = 0; i < m; i++) {
result[i] = [...Array(i + 1).keys()].map(j => i + j * m)
}
let k = num % 2 ? m + m * m : m * m
for (let i = m; i < num; i++, k++) {
result[i] = [...Array(num - i).keys()].map(j => k - j * m).reverse()
}
return result
}
console.table(gen(16))
效果截图如下:
添加回答
举报
0/150
提交
取消