JScript中使用Math.max问题

adamcn 2002-11-22 10:35:03
max 方法

返回给出的零个或多个数值表达式中较大者。

Math.max([number1[, number2[. . . [,numberN]]]])

可选项 number1, number2, . . ., numberN 参数为需要进行比较的数值表达式。

但我现在得到的是前面两个数的最大值。

例:
Matn.max(1,2,3,4,5) = 2

...全文
34 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
adamcn 2002-11-22
  • 打赏
  • 举报
回复
感谢,是个解决的办法。但为什么只比较前面两个?
emu 2002-11-22
  • 打赏
  • 举报
回复
真的耶!

alert(Math.max(1,2,3,4,5))
alert(Math.min(5,4,3,2,1))

都是错的,只比较了前两个。

这样吧:
alert([1,2,3,4,5].sort()[0])
alert([1,2,3,4,5].sort().reverse()[0])
adamcn 2002-11-22
  • 打赏
  • 举报
回复
我是这么用的,但弹出的警告框显示“2”。
Reker熊 2002-11-22
  • 打赏
  • 举报
回复
alert(Math.max(1,2,3,4,5))


—————————————————————————————————
想要游泳的“猪”
emu 2002-11-22
  • 打赏
  • 举报
回复
是版本问题,我早上是在IE5下面试的,现在在IE6下面正常。

qiushuiwuhen 2002-11-22
  • 打赏
  • 举报
回复
<script>
function mymin(){
var ret=Infinity;
for(i=0;i<arguments.length;i++)
if(arguments[i]<ret)ret=arguments[i];
return ret;
}
function mymax(){
var ret=-Infinity;
for(i=0;i<arguments.length;i++)
if(arguments[i]>ret)ret=arguments[i];
return ret;
}
alert(mymin(5,4,3,2,1))
alert(mymin())
alert(mymax(1,2,3,4,5))
alert(mymax())
</script>
blues-star 2002-11-22
  • 打赏
  • 举报
回复
俺地也是正确地~
jery_lee 2002-11-22
  • 打赏
  • 举报
回复
<script>alert(Math.max(1,2,3,4,5))</script>
我的也是正确的。
adamcn 2002-11-22
  • 打赏
  • 举报
回复
我现在用的"土"方法

function mymax(args)
{
.
.
.
}

mymax([1,2,3,4,5])
adamcn 2002-11-22
  • 打赏
  • 举报
回复
是和版本有关,我在另台机器上测试是正确的。

如果我自己写max方法怎么接受不定数量的参数?
像c#中的 public static void Main(int[] args)
qiushuiwuhen 2002-11-22
  • 打赏
  • 举报
回复
版本问题,我这是正确的
<script>alert(Math.max(1,2,3,4,5))</script>
adamcn 2002-11-22
  • 打赏
  • 举报
回复
这个BUG太明显了吧。
emu 2002-11-22
  • 打赏
  • 举报
回复
比尔该死的产品bug多是有口皆碑啦。

87,776

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧