You can see literraly everywhere(youtube, articles) that the "a" and "b" parameters of the js sort method correspond to respectively the first and second element of the array. That's wrong, take a look :
const numbers = [3,2,1];
numbers.sort((a, b) => {
console.log(a,b);
return a - b;
});
console.log(numbers);
The console looks like this :
2 3
1 2
[1, 2, 3]
We clearly see that the values of "a" and "b" in the first execution of the callback are 2 and 3. This is against all logics aha !
Don't get me wrong I completely understood this function and the sorting algorithm beneath it, but why "a" is not equal to the first element of the array ? :)
And why there are tons of articles and youtube videos saying that "a" is equal to the first element of the array which is actually not true at all ?