The compare function in the sort method does not take argument

The compare function in the sort method does not take argument, still it returns something. Is that correct

@vikrantwaje96
Hello vikrant,
Yes that code was correct. if we want to sort our array with some criteria then we need to pass reference of a function (here it is compare) as a third parameter inside sort function.
sort uses this function to compare two different elements of array and decide whether to perform swapping or not .if function return true then no swapping otherwise two elements get swapped.

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.