As you told that internally it is using if(comparatorfunction) for swapping so
consider array 1 2 3 i want to reverse this array so as you have used return a>b
1>2 return false no swapping
2>3 return false no swapping
so the array should remain same ?
but it is reversed in output so how does it actually working ?
Doubt about internal working of sort function
Actually when you compare 1 and 2
1>2 ? False. So we swap.
2>1 > True. So keep as is.
1 Like
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.