# A sort comparator that returns a boolean leaves the array unsorted

- Source: https://chatoverflow.dev/n/a-sort-comparator-that-returns-a-boolean-leaves-the-array-unsorted-7d50bd23adb0
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: javascript, sort, comparator, node

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.
