I have this function:
tests.sort(function (a, b) {
var diff = a.title.localeCompare(b.title);
return diff == 0 ? b.modifiedDate.localeCompare(a.modifiedDate) : diff;
});
I am using it to sort the tests
array first by title
and then by modifiedDate
. The code was working but now I found it gives an error.
When the modifiedDate is null and when this happens the compare fails.
How could I make it so that if the modifiedDate
is null then the sort still works and places those rows after the rows with a modifiedDate that's not null?