当前位置:网站首页>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);
边栏推荐
- Market trend report, technical innovation and market forecast of tabletop dishwashers in China
- Advancedinstaller installation package custom action open file
- 第一章 MapReduce概述
- Chapter 5 yarn resource scheduler
- Read and save zarr files
- Acwing: the 56th weekly match
- Submit several problem records of spark application (sparklauncher with cluster deploy mode)
- useEffect,函數組件掛載和卸載時觸發
- 300th weekly match - leetcode
- Acwing: Game 58 of the week
猜你喜欢
Tree of life (tree DP)
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
QT implementation fillet window
使用jq实现全选 反选 和全不选-冯浩的博客
SQL快速入门
Solve the problem that intel12 generation core CPU single thread only runs on small cores
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
Codeforces Round #801 (Div. 2)A~C
SF smart logistics Campus Technology Challenge (no T4)
【锟斤拷】的故事:谈谈汉字编码和常用字符集
随机推荐
Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
指定格式时间,月份天数前补零
SF smart logistics Campus Technology Challenge (no T4)
Codeforces Round #799 (Div. 4)A~H
Log statistics (double pointer)
Codeforces Round #800 (Div. 2)AC
Chapter 2 shell operation of hfds
音视频开发面试题
Codeforces - 1526C1&&C2 - Potions
SQL快速入门
<li>圆点样式 list-style-type
Educational Codeforces Round 130 (Rated for Div. 2)A~C
【锟斤拷】的故事:谈谈汉字编码和常用字符集
FLV格式详解
CMake Error: Could not create named generator Visual Studio 16 2019解决方法
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
QT realizes window topping, topping state switching, and multi window topping priority relationship
Research Report on market supply and demand and strategy of Chinese table lamp industry
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)