当前位置:网站首页>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);
边栏推荐
- Educational Codeforces Round 130 (Rated for Div. 2)A~C
- Advancedinstaller installation package custom action open file
- Maximum product (greedy)
- Codeforces Round #802(Div. 2)A~D
- Opencv learning log 27 -- chip positioning
- Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
- Installation and configuration of MariaDB
- Study notes of Tutu - process
- 1529. Minimum number of suffix flips
- QT实现圆角窗口
猜你喜欢
Anaconda下安装Jupyter notebook
Programmers, what are your skills in code writing?
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
Suffix expression (greed + thinking)
1689. Ten - the minimum number of binary numbers
QWidget代码设置样式表探讨
C language must memorize code Encyclopedia
921. Minimum additions to make parentheses valid
1005. Maximized array sum after K negations
Browser print margin, default / borderless, full 1 page A4
随机推荐
Install Jupiter notebook under Anaconda
指定格式时间,月份天数前补零
QNetworkAccessManager实现ftp功能总结
Codeforces Round #803 (Div. 2)A~C
Oneforall installation and use
1855. Maximum distance of subscript alignment
Data storage in memory & loading into memory to make the program run
图图的学习笔记-进程
Openwrt source code generation image
Click QT button to switch qlineedit focus (including code)
生成随机密码/验证码
JS call camera
Sword finger offer II 019 Delete at most one character to get a palindrome
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
1013. Divide the array into three parts equal to and
Read and save zarr files
antd upload beforeUpload中禁止触发onchange
Radar equipment (greedy)
分享一个在树莓派运行dash应用的实例。
B - Code Party (girls' competition)