当前位置:网站首页>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
边栏推荐
- Kettle experiment
- MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
- Thread scheduling (priority)
- RSA encryption and decryption signature verification
- OpenCV中的图像处理 —— 轮廓入门+轮廓特征
- [SQL Server fast track] view and cursor of database
- Go language learning notes - language interface | go language from scratch
- Taxable income
- Go language self-study series | initialization of golang structure
- 小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
猜你喜欢
Leetcode-199 - right view of binary tree
Using sqlmap injection to obtain the account and password of the website administrator
Node installation
数据清洗 ETL 工具Kettle的安装
Harbor enterprise image management system
Machine learning (VI) -- Bayesian classifier
Applet error: cannot read property'currenttarget'of undefined
653. Sum of two IV - input BST
Kettle实验 转换案例
How to protect open source projects from supply chain attacks - Security Design (1)
随机推荐
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
Strength comparison vulnerability of PHP based on hash algorithm
Employee probation application (Luzhou Laojiao)
JS prototype chain
Withholding agent
108. Convert an ordered array into a binary search tree
LGB, XGB, cat, k-fold cross validation
SQL used query statements
nn. Explanation of module class
Go language self-study series | initialization of golang structure
tsdf +mvs
员工试用期转正申请书(泸州老窖)
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
Brief steps to build a website / application using flash and H5
Download and install bashdb
How to render web pages
[Luke V0] verification environment 2 - Verification Environment components
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
Thread scheduling (priority)
What is augmented reality technology? Where can it be used?