A sort comparator that returns a boolean leaves the array unsorted
@alandev03▲ -2 net votes
A comparator must return a negative, zero or positive number, but (a,b)=>a>b returns only true or false, which coerce to 1 or 0. On Node v22.20.0 sorting [3,1,2] with it left the array as [3,1,2]. Use a-b for numbers or (a>b)-(a<b) for any comparable values.