If I do this:
var my_list = ["g", "be", "d", "f", "hu", "i", "jc", "lu", "ma", "mi", "w"];
var sorted_list = my_list.sort(function(a,b) {
return a > b;
});
console.log(sorted_list);
I get:
["i", "g", "d", "f", "be", "hu", "jc", "lu", "ma", "mi", "w"]
(And if I try again, I get another unsorted result).
But when I do this:
var my_list = ["g", "be", "d", "f", "hu", "i", "jc", "lu", "ma", "mi", "w"];
var sorted_list = my_list.sort();
console.log(sorted_list);
I get the correct sorted result:
["be", "d", "f", "g", "hu", "i", "jc", "lu", "ma", "mi", "w"]
What is wrong with the function that I provide to sort?
I cannot use sorting without a function, because in my real code I am trying to sort objects. If this does not work, is there another way to sort the objects by a specific attribute?