Where do the arguments a and b come from in this sorting function?
Are they passed automatically?
dir = "asc"
sortArray = new Array("hello", "Link to Google", "zFile", "aFile");
//sort array
if (dir == "asc") {
sortArray.sort(function(a, b) {
return a.toLowerCase() > b.toLowerCase()
});
} else {
sortArray.sort(function(a, b) {
return b.toLowerCase() > a.toLowerCase()
});
}
for (var i = 0; i < sortArray.length; i++) {
console.log(sortArray[i]);
}
Yes.
You are creating an anonymous comparator function, which the
sortfunction calls whenever it needs to compare two objects.