当前位置:网站首页>JS encapsulates the method of array inversion -- Feng Hao's blog
JS encapsulates the method of array inversion -- Feng Hao's blog
2022-07-06 16:39:00 【Feng Hao (grow up)】
Ideas : We use two loops Traverse the previous element and the next element respectively ,
Then define an empty variable , Make a position change
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);

边栏推荐
- Codeforces - 1526C1&&C2 - Potions
- QT simulates mouse events and realizes clicking, double clicking, moving and dragging
- 新手必会的静态站点生成器——Gridsome
- Hbuilder X格式化快捷键设置
- Li Kou - 298th weekly match
- It is forbidden to trigger onchange in antd upload beforeupload
- 业务系统从Oracle迁移到openGauss数据库的简单记录
- Generate random password / verification code
- Codeforces Round #802(Div. 2)A~D
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
猜你喜欢

Chapter 5 detailed explanation of consumer groups

解决Intel12代酷睿CPU单线程只给小核运行的问题

Tree of life (tree DP)

Chapter 7__ consumer_ offsets topic

解决Intel12代酷睿CPU单线程调度问题(二)

Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it

MariaDB的安装与配置

Log statistics (double pointer)

Chapter 6 rebalance details

Advancedinstaller installation package custom action open file
随机推荐
Effet d'utilisation, déclenché lorsque les composants de la fonction sont montés et déchargés
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Research Report on market supply and demand and strategy of Chinese table lamp industry
Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
FLV格式详解
MP4格式详解
顺丰科技智慧物流校园技术挑战赛(无t4)
antd upload beforeUpload中禁止触发onchange
Calculate the time difference
第6章 Rebalance详解
视频压缩编码和音频压缩编码基本原理
Acwing: the 56th weekly match
Chapter 5 namenode and secondarynamenode
Spark独立集群动态上线下线Worker节点
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Spark独立集群Worker和Executor的概念
(POJ - 3186) treatments for the cows (interval DP)
Chapter 6 datanode
sublime text 代码格式化操作
Codeforces Round #803 (Div. 2)A~C