#값으로 변환 전
var numbers = [20, 10, 9,8,7,6,5,4,3,2,1];
function sortfunc(a,b){
console.log(a,b);
if(a > b){
return 1;
} else if(a < b){
return -1;
} else {
return 0;
}
}
console.log(numbers.sort(sortfunc));
#값으로 변환 후
var numbers = [20, 10, 9,8,7,6,5,4,3,2,1];
var sortfunc = function(a,b){
return a-b;
}
console.log(numbers.sort(sortfunc));