I've got an array of objects with names, like so:
myArray = [
{name : 'foo'},
{name : 'bar'},
{name : 'Foo'}
]
I want to sort these object alphanumerically by name, and was using the following sort function to do so:
myArray.sort(function(a,b){
return a.name > b.name;
});
This seems to work, but I can't find anything in the spec with regards to how sort
is supposed to function when the comparison function returns booleans. This DOESN'T seem to follow the requirement that if a > b
returns something greater than zero, a < b
returns something less than zero, and a === b
returns something equal to zero.
What I'm wondering is, will using a function that returns a boolean work consistently for sorting across browsers?