当前位置:网站首页>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
边栏推荐
- [original] use system Text. JSON formats the JSON string
- MySQL of database -- overview and installation
- Single sign on SSO
- 基于ThinkPHP5版本TRC20-资金归集解决方案
- [58] length of the last word [leetcode]
- npm ERR! network
- STM32 and FreeRTOS stack parsing
- Number of islands
- DJ music management software pioneer DJ rekordbox
- Give the method of instantiating the object to the new object
猜你喜欢
[58] length of the last word [leetcode]
Kettle experiment
Using JS to realize a thousandth bit
Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
653. 两数之和 IV - 输入 BST
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
机器学习(六)——贝叶斯分类器
nn. Explanation of module class
501. Mode in binary search tree
Applet error: cannot read property'currenttarget'of undefined
随机推荐
What is augmented reality technology? Where can it be used?
Find the sum of simple types of matrices
Taxable income
Single sign on SSO
Your guide to lowering your cholesterol with TLC (continuously updated)
Pctp test experience sharing
Notes on xctf questions
Trc20 fund collection solution based on thinkphp5 version
Thread scheduling (priority)
NLLLoss+log_ SoftMax=CE_ Loss
机器学习(六)——贝叶斯分类器
Resource packaging dependency tree
On array replication
653. Sum of two IV - input BST
Rembg split mask
MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
Summary of common concepts and problems of linear algebra in postgraduate entrance examination
Harbor enterprise image management system
小女孩行走
JS prototype chain