使用 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 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
以上就是查找数组中的最大数字 - JavaScript的详细内容,更多请关注php中文网其它相关文章!
版权声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系 yyfuon@163.com