Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
757 B
43 lines
757 B
var buildRegex = new RegExp('>([0-9]+)(?:[.]([0-9]+))?<');
|
|
|
|
function customSort(name, order, data) {
|
|
order = order === 'asc' ? 1 : -1;
|
|
|
|
data.sort(function (a, b) {
|
|
a = a[name];
|
|
b = b[name];
|
|
|
|
if (!a) {
|
|
return 1;
|
|
} else if (!b) {
|
|
return -1;
|
|
}
|
|
|
|
if (name === 'builds') {
|
|
return buildSort(a, b) * order;
|
|
} else {
|
|
if (a < b) {
|
|
return -order;
|
|
} else if (a === b) {
|
|
return 0;
|
|
} else {
|
|
return order;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function buildSort(a, b) {
|
|
a = buildRegex.exec(a);
|
|
b = buildRegex.exec(b);
|
|
|
|
var aMajor = parseInt(a[1]);
|
|
var bMajor = parseInt(b[1]);
|
|
if (aMajor !== bMajor) {
|
|
return aMajor - bMajor;
|
|
}
|
|
|
|
var aMinor = a[2] ? parseInt(a[2]) : 0;
|
|
var bMinor = b[2] ? parseInt(b[2]) : 0;
|
|
return aMinor - bMinor;
|
|
}
|
|
|