84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
找出数字数组中最大的元素(使用Math.max函数)
function findMax(arr) {arr.reduce(function(pre,cur){return Math.max(pre,cur)}) } var arr=[1,2,3,4,5,1,12,21]; alert(findMax(arr));//出来是undefined???
闭关修行中......
你的function没有返回,arr.reduce出来的结果没人接盘。
试试
function findMax(arr) { return arr.reduce(function(pre, cur) { return Math.max(pre,cur); }); } var arr = [1,2,3,4,5,1,12,21]; console.log(findMax(arr));
Math.max.apply(this,arr)
你的function没有返回,arr.reduce出来的结果没人接盘。
试试
Math.max.apply(this,arr)