当前位置:网站首页>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
边栏推荐
- Number of islands
- Common errors of VMware building es8
- NLLLoss+log_ SoftMax=CE_ Loss
- 《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
- Canary publishing using ingress
- Resource packaging dependency tree
- Go language learning notes - language interface | go language from scratch
- MySQL小练习(仅适合初学者,非初学者勿进)
- 机器学习(六)——贝叶斯分类器
- 员工试用期转正申请书(泸州老窖)
猜你喜欢

数据清洗 ETL 工具Kettle的安装

Brief steps to build a website / application using flash and H5

Applet error: cannot read property'currenttarget'of undefined

Applet error: should have URL attribute when using navigateto, redirectto or switchtab

npm ERR! network

NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’

Node installation

Two methods of building Yum source warehouse locally

108. 将有序数组转换为二叉搜索树

Detailed explanation of delete, truncate and drop principles in MySQL database
随机推荐
Failed to download esp32 program, prompting timeout
JS prototype chain
Strength comparison vulnerability of PHP based on hash algorithm
MySQL of database -- overview and installation
Using JS to realize a thousandth bit
Is Zhongyan futures safe and reliable?
Two ways for flutter providers to share data
小程序报错:Cannot read property 'currentTarget' of undefined
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
501. 二叉搜索树中的众数
Employee probation application (Luzhou Laojiao)
Chapter VIII project stakeholder management of information system project manager summary
nn. Explanation of module class
资源打包关系依赖树
108. 将有序数组转换为二叉搜索树
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
Wechat applet catchtap = "todetail" event problem
Kettle experiment (III)
EmuElec 编译总结
Write down the post order traversal of the ~ binary tree