当前位置:网站首页>js封装数组反转的方法--冯浩的博客
js封装数组反转的方法--冯浩的博客
2022-07-06 09:29:00 【冯浩(grow up)】
思路:我们使用两个循环 分别遍历出前一个元素和后一个元素,
然后定义一个空的变量,进行位置调换
function reversal(arr){
for(var i =0 ;i<arr.length;i++){
for(var j =i+1;j<arr.length;j++){
var temp ;
temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
var arr = ["a","b","c","d"];
console.log(arr);
reversal(arr);
console.log(arr);
边栏推荐
- 力扣:第81场双周赛
- (POJ - 3685) matrix (two sets and two parts)
- Luogu P1102 A-B number pair (dichotomy, map, double pointer)
- QWidget代码设置样式表探讨
- 栈的经典应用—括号匹配问题
- Socket communication
- Input can only input numbers, limited input
- Programmers, what are your skills in code writing?
- QT实现窗口渐变消失QPropertyAnimation+进度条
- Radar equipment (greedy)
猜你喜欢
Codeforces Round #801 (Div. 2)A~C
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Li Kou - 298th weekly match
树莓派4B安装opencv3.4.0
1903. Maximum odd number in string
< li> dot style list style type
SF smart logistics Campus Technology Challenge (no T4)
Kubernetes cluster deployment
Anaconda下安装Jupyter notebook
Borg maze (bfs+ minimum spanning tree) (problem solving report)
随机推荐
window11 conda安装pytorch过程中遇到的一些问题
QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
Summary of FTP function implemented by qnetworkaccessmanager
Write web games in C language
Auto. Getting started with JS
力扣:第81场双周赛
AcWing——第55场周赛
409. Longest palindrome
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
Openwrt source code generation image
双向链表—全部操作
Oneforall installation and use
力扣——第298场周赛
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Read and save zarr files
Codeforces Round #803 (Div. 2)A~C
Codeforces Round #797 (Div. 3)无F
Interesting drink
The concept of C language array
Educational Codeforces Round 130 (Rated for Div. 2)A~C