下面给出的代码给出了一个错误arguments.sort
不是函数。是因为论点对象不能直接更改?或者是别的什么。Javascript“not a function”
任何帮助,将不胜感激。
function highest()
{
return arguments.sort(function(a,b){
return b - a;
});
}
assert(highest(1, 1, 2, 3)[0] == 3, "Get the highest value.");
assert(highest(3, 1, 2, 3, 4, 5)[1] == 4, "Verify the results.");
的assert
功能如下(以防万一)
function assert(pass, msg){
var type = pass ? "PASS" : "FAIL";
jQuery("#results").append("<li class='" + type + "'><b>" + type + "</b> " + msg + "</li>");
}
谢谢,这有很大的帮助。 – clu3Less 2013-03-07 09:45:47
但是这不返回一个数组:x – Esailija 2013-03-07 09:47:12
@Esailija:没错,没有注意到它返回一个'arguments'对象。对于这种情况应该没问题,但是OP可能需要一个实际的数组。 – elclanrs 2013-03-07 09:50:29