汇才同飞教育汇才同飞学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › zhangjiafu › 日志

【Math】模拟实现max()/min()

2020-12-01 16:42:40 查看(21) 回复(0)

提示:

编写函数,实现max()功能,要求传入任意一组数字,返回最大的数字,

使用函数的arguments属性实现

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        function f() {
            let arr=f.arguments;
            let min=arr[0]
            for (let i = 1; i <arr.length ; i++) {
            if(min>arr[i]){
                min=arr[i]
            }
            }
            return min
        }
      min=f(3,4,6,8,10,1,2);
        document.write(min);
    </script>
    //找较大的数
   <!-- <script>
        function f() {
            let arr=f.arguments;
            let max=arr[0]
            for (let i = 1; i <arr.length ; i++) {
                if(max<arr[i]){
                    max=arr[i]
                }
            }
            return max
        }
        max=f(3,4,6,8,10,1,2 );
        document.write(max);
    </script>-->

</head>
<body>
</body>
</html>

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.cn 备案号:京ICP备17025800号-2

f1208.com 备案号:京ICP备14030918号-1

返回顶部