关于a-b和b-a有关的排序问题
function sortNum(a,b) {
return b-a;
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
这里函数sortNum()里面执行的return b-a;意思返回b-a的值。我的理解是调用的时候不应该返回的是差值吗?比如数组var myarr = new Array("80","16","50","6","100","1");调用返回的应该是前后两数的差值啊,怎么就变成了排序而不是差值呢?一直理解不了,求大神们赐教