08-20-2018, 03:39 PM
Hi,
Nice idea :-)
Below is the sort routine for upcoming 4.3 release. It uses Intl.Collator() and collator.compare(a, b) instead of localeCompare() which is super slow. Its in a try/catch block to cover Browsers/Javascript that may not support collator, and its case insensitive (sensitivity: 'base').
Give it a try. It should be fast :-)
Nice idea :-)
Below is the sort routine for upcoming 4.3 release. It uses Intl.Collator() and collator.compare(a, b) instead of localeCompare() which is super slow. Its in a try/catch block to cover Browsers/Javascript that may not support collator, and its case insensitive (sensitivity: 'base').
Give it a try. It should be fast :-)
Code:
// sort the lists
allGenres.sort();
// sort using natural ordering
try {
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
allArtists.sort(function(a, b) {
a = removeArticles(a);
b = removeArticles(b);
return collator.compare(a, b);
});
allAlbumsTmp.sort(function(a, b) {
a = removeArticles(a['album']);
b = removeArticles(b['album']);
return collator.compare(a, b);
});
}
// fallback to default ordering
catch (e) {
allArtists.sort(function(a, b) {
a = removeArticles(a.toLowerCase());
b = removeArticles(b.toLowerCase());
return a > b ? 1 : (a < b ? -1 : 0);
});
allAlbumsTmp.sort(function(a, b) {
a = removeArticles(a['album'].toLowerCase());
b = removeArticles(b['album'].toLowerCase());
return a > b ? 1 : (a < b ? -1 : 0);
});
}