1 means that a is greater than b by the ordering criterion, while -1 means that a is less than b by some ordering criterion. All elements are compared against each other that way until the array is sorted. a === b ? 0 means that if they are equal then they don’t move, and as far as I know you can drop that condition altogether, at least for this piece of code. Btw I just quoted MDN, you might wanna take a look at it. Array.prototype.sort() - JavaScript | MDN
Consider this
let nums = [1, 2, 1, 3]
function sorted(a) {
return a.sort((a, b) => {
return a < b ? 1 : -1
})
}
console.log(sorted(nums))