I have an observable array of objects that are used to populate a table with sortable columns.
My sorting function works perfectly and is based on the following simplification:
self.sortTheItems = function () {
self.items.sort(function (l, r) {
var rslt = l === r ? 0 : l < r ? -1 : 1;
return self.sortAscending() ? rslt : -rslt;
});
}
How could this be changed to always place values of 0 last both for ascending and descending sorting?
e.g. Unsorted values: 3,1,2,2,0,1,3,0
Descending: 3,3,2,2,1,1,0,0
Ascending: 1,1,2,2,3,3,0,0