Dear all,
Please help me with the logic behind the sort() with call back function.
Code:
>[1,3,12,5,23,18,7].sort();
which will retu
Code:
<<[1,12,18,23,3,5,7]
In order to sort the numbers correctly a callback function is used.
Code:
function compareNumbers(a,b){
return a-b;
}
Code:
>[1,3,12,5,23,18,7].sort(compareNumbers);
which will retu
Code:
<<[1,3,5,7,12,18,23]
I still don't understand the logic how the compareNumbers function sorted this out. Please help.
برچسب:
نویسنده: آیلین رضوانی
تاريخ: چهارشنبه
22 آذر
1396 ساعت: 18:28