How sort function uses compare as parameter

sort(start,end,compare).In compare funtion if(a<b) is for ascending order. and if(a>b) is for descending order. How it works