Improved sorting to be stable

This commit is contained in:
Sebastian Lay 2021-08-31 16:28:51 +02:00
parent 6f58484e5e
commit c1f9e350b8
No known key found for this signature in database
GPG Key ID: A699D9B80D6068AA

View File

@ -44,21 +44,19 @@ const app = new Vue({
var sortBy = this.sortBy;
var sortDir = this.sortDir;
var sorted = this.filteredfilms.sort(function (a, b) {
var first = a.name.toLowerCase() + a.format;
var second = b.name.toLowerCase() + b.format;
switch(sortBy) {
case 'popularity':
return a.popularity - b.popularity;
return a.popularity - b.popularity || first.localeCompare(second);
case 'name':
var first = a.name.toLowerCase() + a.format;
var second = b.name.toLowerCase() + b.format;
if(first < second) return -1;
if(first > second) return 1;
return 0;
return first.localeCompare(second);
case 'price':
return a.price - b.price;
return a.price - b.price || first.localeCompare(second);
case 'iso':
return a.iso - b.iso;
return a.iso - b.iso || first.localeCompare(second);
case 'date':
return a.launched - b.launched;
return a.launched - b.launched || first.localeCompare(second);
}
});
if(sortDir === 'asc') {