How can i judge beforehand that will my array be sorted in ascending or descending order ?
like when i do “return a>b;”, it yeilds ascending order, so how can i be sure, that i will get ascending order if i do (a>b) even before seeing the output ?
Comparator in sort
because it will return a by comparing with b and if it satisfies the condition that is a is greater than b this function call will go till the end of array. and to make sure that it will return numbers in ascending order try doing a < b.
hey @rachit.prfnl sort function automatically sorts in ascending order . its due to its working . also it provides a third argument if you want to sort in descending order u have to pass compare and a>b return means sorting in descending order . it is a whole inbuilt function so it is gauranteed it will sort it in descending order after passing comparator.
