这部分是从书“学习
PHP,MysqL和
Javascript by.罗宾尼克松”的错误?
numbers = [7,23,6,74]; numbers.sort(function(a,b){return a - b});
产量为6,7,74
这本书说:
If the anonymous function inside sort() returns a value greater than zero,the sort assumes a comes before b.
If the anonymous function inside sort() return a value less than zero,the sort assumes b comes before a.
The sort runs this function across all the values in the array to determine their order.
这是错的吗因为….
这里是7
这里是23
7 – 23 = -16 //小于零的数字.书中说b应该在a之前.
所以最终输出应该是74,6