当前位置:网站首页>JS - max. of array cases
JS - max. of array cases
2022-06-13 08:22:00 【tingkeaiii】
One 、 subject
Find an array [2,6,1,77,52,25,7] The maximum
Two 、 Source code
<script>
// Find an array [2,6,1,77,52,25,7] The maximum
var arr = [2, 6, 1, 77, 52, 25, 7];
var big = 0;
for (var i = 1; i < arr.length; i++) {
if (arr[big] > arr[i]) {
} else {
arr[big] = arr[i];// Extract the one that is larger than the last digit
}
}
console.log(arr[big]);/* Output 77*/
</script>
3、 ... and 、 Ideas
The index number that declares a maximum value . Compare the maximum value with the array elements in turn , Choose which is the largest value .
- The index number that declares a maximum value 0,
, Is to select the first element to match . - Since the maximum index value and the first array element are obtained here 2, It should be 2 And the next array element 6 To compare , therefore i It should start from the second of the array , Namely i=1
- When i=1,2 And 6 Match ,6 Bigger , That is, the index number is 1 It's bigger , Assign a larger element to arr[big], such 6 It is extracted and compared with the following values .
- If the following value is greater than 6 Big , Then the value is updated to the maximum value , If less than 6, Do nothing , The maximum is still 6.
边栏推荐
- PHP isset() method ignores data error handling caused by null parameter value
- [game theory complete information static game] Nash equilibrium
- Rust writes near smart contract
- 【博弈论-完全信息静态博弈】 Nash均衡
- Format_ String_ Server
- DNS domain name resolution service
- Microservice Project Construction II: database design
- Detailed explanation of digital certificate and Ca
- Win10系统如何修改桌面路径
- sizeof、strlen求字符长度
猜你喜欢

How about a well-known food material distribution information management system?

Remote access and control

Create a substrate private network

STM32CubeMX的下载和安装方式

HCIP_ Static experiment

酒水批发行业应当如何高效管理商品与库存

CCNP_ BT-MGRE

Introduction to dfinity (ICP) -1

SQL injection question type (manual injection +sqlmap)

How to efficiently manage commodities and inventory in the beverage wholesale industry
随机推荐
Buuctf web (III)
Notes on development experience: TP5 exp query, SQL analysis, JQ, applet, right-click menu, Linux skills, shell skills, mysql, etc
ERP basic data Huaxia
Win10系统如何修改桌面路径
IPFs cluster setup process
Cosmos Starport installation and startup
Guidance process and service control
Using KVM to create three virtual machines that can communicate with local area network
AcWing 1977. Information relay (base ring tree, parallel search set)
How to download and install stm32cubemx
Notes on MySQL transaction not automatically submitting
CCNP_ Summary (Continued)
微服务项目搭建三:自动生成代码
How to efficiently manage commodities and inventory in the beverage wholesale industry
Maternal and infant supplies wholesale industry uses management software to improve efficiency and realize cost reduction and efficiency increase
Differences between Merkle DAG and Merkle tree
MySQL query exercise 3
学习记录4: einops // cudnn.benchamark=true // hook
Reverse order and comparison of strings
Overview of cross chain protocol IBC