当前位置:网站首页>js案例之求最大值,反转数组,冒泡排序
js案例之求最大值,反转数组,冒泡排序
2022-04-23 06:25:00 【小白蛋挞】
//求最大值
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));
//反转数组
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);
// 冒泡排序
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);
版权声明
本文为[小白蛋挞]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_61547956/article/details/124127738
边栏推荐
猜你喜欢

Nacos/sentinel网关限流和分组 (代码)

MySQL index

Authorization+Token+JWT

redis连接出错 ERR AUTH <password> called without any password configured for the default user.

SAP PI/PO登录使用及基本功能简介

SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)

int a = 1存放在哪

SAP DEBUG调试FOR IN、REDUCE等复杂的语句

Super classic & Programming Guide (red and blue book) - Reading Notes

反思|开启B站少女心模式,探究APP换肤机制的设计与实现
随机推荐
Reflection on the systematic design of Android audio and video caching mechanism
MySQL storage engine
超级宝典&编程指南(红蓝宝书)-读书笔记
VR、AR、MR的区别与应用,以及对AR技术的一些实现原理
SAP PI/PO rfc2Soap 发布rfc接口为ws示例
Learn to use search engines
Nacos / sentinel gateway current limiting and grouping (code)
SAP PI/PO登录使用及基本功能简介
js之节点操作,为什么要学习节点操作
SAP CR传输请求顺序、依赖检查
Visualization Road (IX) detailed explanation of arrow class
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
对js中argumens的简单理解
技能点挖坑
13.用户和权限管理
[Ted series] how does a habit change my life
BTREE, B + tree and hash index
[CodeForces - 208E] Blood Cousins(k代兄弟问题)
‘npm‘不是内部或外部命令,也不是可运行的程序 或批处理文件
redis连接出错 ERR AUTH <password> called without any password configured for the default user.