当前位置:网站首页>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);
边栏推荐
猜你喜欢
第 300 场周赛 - 力扣(LeetCode)
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
TCP's three handshakes and four waves
Frida hook so layer, protobuf data analysis
Codeforces Round #799 (Div. 4)A~H
Installation and configuration of MariaDB
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
Vs2019 initial use
QT implementation fillet window
(POJ - 3685) matrix (two sets and two parts)
随机推荐
栈的经典应用—括号匹配问题
Advancedinstaller installation package custom action open file
300th weekly match - leetcode
C language is the watershed between low-level and high-level
QT implementation fillet window
useEffect,函数组件挂载和卸载时触发
Quick to typescript Guide
力扣:第81场双周赛
QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
Opencv learning log 26 -- detect circular holes and mark them
Frida hook so layer, protobuf data analysis
去掉input聚焦时的边框
QT implementation window gradually disappears qpropertyanimation+ progress bar
What is the difficulty of programming?
Codeforces Round #800 (Div. 2)AC
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
input 只能输入数字,限定输入
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
Specify the format time, and fill in zero before the month and days
Codeforces Round #799 (Div. 4)A~H