有谁知道这是为什么吗?a-b就能升序,b-a就能降序????????
var numbers=[2,3,4,45,234,234,23,454,4,3,45,3,2,3]
numbers.sort(function(a,b){
return a-b
})
升序
return [2, 2, 3, 3, 3, 3, 4, 4, 23, 45, 45, 234, 234, 454]
numbers.sort(function(a,b){
return b-a
})
降序
return [454, 234, 234, 45, 45, 23, 4, 4, 3, 3, 3, 3, 2, 2]