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