当前位置:网站首页>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
边栏推荐
猜你喜欢

《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路

What is monitoring intelligent playback and how to use intelligent playback to query video recording
![[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)](/img/c9/43a63f526068ef6a3e4964a22c5a1f.png)
[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)

Download and install bashdb

Write down the post order traversal of the ~ binary tree

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

AQS & reentrantlock implementation principle

Using sqlmap injection to obtain the account and password of the website administrator

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

机器学习(六)——贝叶斯分类器
随机推荐
MySQL of database -- Fundamentals
The most concerned occupations after 00: civil servants ranked second. What was the first?
How to read excel table to database
Rembg split mask
Harbor enterprise image management system
js 原型链的深入
Canary publishing using ingress
Emuelec compilation summary
错题汇总1
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
小程序报错:Cannot read property 'currentTarget' of undefined
[boutique] using dynamic agent to realize unified transaction management II
[C language] document operation
GUI, CLI and UNIX Philosophy
108. 将有序数组转换为二叉搜索树
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
501. Mode in binary search tree
Non duplicate data values of two MySQL query tables
Brush classic topics
Go language learning notes - exception handling | go language from scratch