a = [3, 1, 2];
function b(v1, v2) {
console.log('c', v1, v2);
return 0
};
a.sort(b);
console.log(a);
a result of this script is like this
c 31
c 12
[3, 1, 2]
my question is
-
Why is the function b being called twice?
-
And
in the first log
console.log(‘c’, v1, v2);
why the v1 value is the first array value of a. it’s “3”
also why v2 is the second array value of “a”
in the second log
console.log(‘c’, v1, v2);
Why are the 2nd and 3rd values of the array in v1, v2
the result is “c 1 2”
I can’t understand