// 题目:利用函数求任意一个数组中的最大值/* 思路:利用for循环遍历数组sout[5,2,66,111,34,55],其中用if判断sout[i]>sout[i+1]则将值赋予MAX变量;最后return max */function getSout(sout) {var max = sout[0];for (i = 0; i < sout.length; i++) {if (sout[i] + 1 > max) {max = sout[i]}}return max;}var re = getSout([5, 2, 66, 151, 34, 123]);console.log(re);/*--------------------------------------------------------*/// 注意:return具有终止函数的效果;retuen只能返回一个值function one(n1, n2) {return n1 + n2;// return值之后,不再进行下面的代码;console.log('hihihi');}// 输出:console.log(one(4, 5));/* 返回结果为9 *///--------------------------------// retuen只能返回一个值;function two(n1, n2) {// 最终只返回尾数n2// return n1, n2;}// console.log(two(5, 7));/* 返回结果为7 *///--------------------------------// 如果需要返回多个变量,只能用数组的方式返回function three(n1, n2) {return arr = [n1, n2]}var re = (three(25, 22));console.log(re)
