js快速找出数组中的最大值
时间:2015-11-14 17:51:39
收藏:0
阅读:308
对于一个数组,怎样才能最快找出数组中的最大值
var nums = [1,56,78,345,67,89,3423,34,5,7]; var max = 0; for(var i=0; i<nums.length; i++){ if(nums[i] > max){ max = nums[i]; } } console.log( "第一种排序方式:", max ); console.log(‘第二种排序方式:‘,Math.max(1,56,86,2,36,53,45,143,56,89)); nums.sort(function(a, b){return a-b}); console.log("第三种排序方式:", nums[0]);
原文:http://www.cnblogs.com/fuxiang-yang/p/4964733.html
评论(0)