当前位置:网站首页>Realization of serpentine digital lattice Write a cube function with the input parameter of num. the requirements are as follows through JS: when num=3, the output table effect is: [[1,2,3] [6,5,4] [7
Realization of serpentine digital lattice Write a cube function with the input parameter of num. the requirements are as follows through JS: when num=3, the output table effect is: [[1,2,3] [6,5,4] [7
2022-07-21 20:40:00 【Bug tune teacher】
function snakeMatrix(num) {
var arr1 = new Array(num);// Initial unidimensional array
for(let k=0;k<num;k++){
arr1[k] = new Array(num); Initial 2D array
}
for(let i=0;i<num;i++){
for(let j=num-1;j>=0;j–){
// num The square of is just arr1[num][num] The maximum number of , So you only need to use num Subtract the array subscript from the square of
arr1[i][j] = num*(i+1)-j;
}
if(i%2==0){
// If i For the even , Reverse
arr1[i] = arr1[i].reverse();
}
}
return arr1;
}
console.log(snakeMatrix)
边栏推荐
- Moment custom time interval
- 动态监听DOM元素的高度
- Stop pulling, stop pulling, read it in pieces
- JS to realize horizontal and vertical screen switching of monitoring mobile terminal
- 图片、头像上传
- 第五局 阿卡丽教学局 下
- Deep analysis recursion
- Click the back button to return to the previous page
- 17.【setw()函数的运用】
- Jump and receive parameters of JS page
猜你喜欢
自定义MVC原理
Mise en œuvre personnalisée du cadre MVC
[C language] please fly the detailed ability functions and arrays back to the country of light
Crud of MySQL
使用tailwind在谷歌浏览器上,button会出现蓝色背景的问题
解决safari浏览器拦截window.open
P1364 hospital settings
Object. prototype. toString. The principle of call()
General paging 01
JS使用递归实现对象的深拷贝
随机推荐
MySQL之函数
18.【指向二维数组的指针注意事项】
移动端 pc端 小程序 UI框架选择
Deep analysis recursion
How to view your own edition of eigen
codeforces 1647A Madoka and Math Dad
First Working Day~
如何取到第一个子元素下的第二个子元素
Codeforces 1642B Power Walking
如何通过IP共享文件
专栏开设的意义
Deep analysis of string -- strcat & strncat
MySQL account management Database building and four engines
14.【string函数上章】
图片上传
C language to achieve three chess games - pattern open version(
Why use the fast and slow pointer to find the link of the linked list, and the fast pointer and the slow pointer must meet?
P1364 hospital settings
The feeling of an elegant "interview"
Image upload