Cari nombor maksimum daripada tatasusunan integer positif menggunakan JavaScript
//findMaxNumber.js function findMaxNumber(numbers) { //Initializes result to track the maximum number, starting at 0. let result = 0; //Stores the length of the numbers array for use in the loop. const numbersLength = numbers.length; //Check if the array is not empty before processing it. if (numbersLength > 0) { //Loops through each number in the array. for (let i = 0; i < numbersLength; i++) { //Compare each number to the result to check if it's larger. if (numbers[i] > result) { //Updates result with the current number if it's the largest result = numbers[i]; } } console.log(result); return result; } return result; } findMaxNumber([5, 33, 47, 103]);
> 103
Atas ialah kandungan terperinci Cari nombor maksimum dalam tatasusunan - JavaScript. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!