0

I am trying to understand how a and b are used in the sort() method but I am having trouble understanding why the "a" argument of this array is [3,7] and [2,5] rather than the element at array[0], which would be the first argument [1,4] below is the example of the code I have been experimenting with

const array = [[1,4],[3,7],[2,5]];
array.sort((a,b)=>console.log(a))
  • 3
    it is unimportant *which* element `a` and `b` refer to and it may actually vary between implementations. What is important is the comparator indicating the order they should be returned in. – pilchard Feb 07 '23 at 08:29
  • Some interesting details: https://stackoverflow.com/questions/6640347/javascript-native-sort-method-code – Kostas Minaidis Feb 07 '23 at 12:03

0 Answers0