如何设计算法以查找数字列表中的最大数字?

时间:2010-08-01 17:25:45

标签: javascript algorithm

我还需要将我的答案转换为显示最大值的javascript代码。

2 个答案:

答案 0 :(得分:3)

alert(Math.max(13, 42, 86, 3, 25)); // 86

答案 1 :(得分:0)

我想你只需要以下内容:

var mx = list[0];
for (i=1; i<length(list); i++)
    mx = Math.max(mx, list[i])

alert(mx)