当前位置:网站首页>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);
边栏推荐
- 第6章 DataNode
- 原生js实现全选和反选的功能 --冯浩的博客
- QT implementation fillet window
- 顺丰科技智慧物流校园技术挑战赛(无t4)
- Spark independent cluster dynamic online and offline worker node
- QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
- 力扣leetcode第 280 场周赛
- FLV格式详解
- QT implementation window gradually disappears qpropertyanimation+ progress bar
- 解决Intel12代酷睿CPU单线程调度问题(二)
猜你喜欢
音视频开发面试题
Kubernetes集群部署
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Local visualization tools are connected to redis of Alibaba cloud CentOS server
Li Kou: the 81st biweekly match
Log statistics (double pointer)
第五章 Yarn资源调度器
第2章 HFDS的Shell操作
Chapter 2 shell operation of hfds
第6章 DataNode
随机推荐
Spark的RDD(弹性分布式数据集)返回大结果集
力扣——第298场周赛
(lightoj - 1323) billiard balls (thinking)
Problem - 1646C. Factorials and Powers of Two - Codeforces
The concept of spark independent cluster worker and executor
AcWing——第55场周赛
< li> dot style list style type
Educational Codeforces Round 130 (Rated for Div. 2)A~C
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
875. Leetcode, a banana lover
力扣:第81场双周赛
CMake速成
Pytorch extract skeleton (differentiable)
Effet d'utilisation, déclenché lorsque les composants de la fonction sont montés et déchargés
顺丰科技智慧物流校园技术挑战赛(无t4)
浏览器打印边距,默认/无边距,占满1页A4
Li Kou - 298th weekly match
Solve the problem that intel12 generation core CPU single thread only runs on small cores
第五章 Yarn资源调度器
Classic application of stack -- bracket matching problem