当前位置:网站首页>JS case to find the maximum value, reverse the array, bubble sort
JS case to find the maximum value, reverse the array, bubble sort
2022-04-23 09:22:00 【Small white egg tart】
// For maximum
function getMax() {
var max = arguments[0];
for (var i = 1; i <
arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
console.log(getMax(1, 2, 3));
console.log(getMax(1, 2, 3, 4, 5));
// Inversion array
function reserve() {
var newarr = [];
for (var i = arguments.length - 1; i >= 0; i--) {
newarr[newarr.length] = arguments[i];
}
return newarr;
}
var arr = reserve(1, 3, 4);
console.log(arr);
// Bubble sort
function bubble(arr) {
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
var temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
var arr1 = bubble([3, 2, 5, 6, 1]);
console.log(arr1);
版权声明
本文为[Small white egg tart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624114409.html
边栏推荐
- 112. 路径总和
- Sql1 [geek challenge 2019]
- Go language self-study series | golang nested structure
- Summary of wrong questions 1
- OpenCV中的图像处理 —— 轮廓入门+轮廓特征
- Summary of common concepts and problems of linear algebra in postgraduate entrance examination
- ATSS(CVPR2020)
- Installation of data cleaning ETL tool kettle
- [original] use system Text. JSON formats the JSON string
- 考研线性代数常见概念、问题总结
猜你喜欢
![Buuctf [actf2020 freshman competition] include1](/img/47/b8f46037f7e9476b8e01e8d6a7857a.png)
Buuctf [actf2020 freshman competition] include1

Leetcode-199 - right view of binary tree

kettle庖丁解牛第14篇之JSON输入

Machine learning (VI) -- Bayesian classifier

Strength comparison vulnerability of PHP based on hash algorithm
![[58] length of the last word [leetcode]](/img/c5/3ba1fe5a81593d9576bb597f0d5f45.png)
[58] length of the last word [leetcode]

Data visualization: use Excel to make radar chart

Common errors of VMware building es8

npm ERR! network

Go language learning notes - language interface | go language from scratch
随机推荐
Installation of data cleaning ETL tool kettle
GoLand debug go use - white record
Go language learning notes - slice, map | go language from scratch
Group Backpack
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
NLLLoss+log_ SoftMax=CE_ Loss
Leetcode-199 - right view of binary tree
LGB, XGB, cat, k-fold cross validation
Secrets in buffctf file 1
Failed to download esp32 program, prompting timeout
Open services in the bottom bar of idea
Go language self-study series | golang structure as function parameter
Kettle experiment
Principle of synchronized implementation
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
机器学习(六)——贝叶斯分类器
Unfortunately, I broke the leader's confidential documents and spit blood to share the code skills of backup files
Kettle experiment
Using JS to realize a thousandth bit
Strength comparison vulnerability of PHP based on hash algorithm