switch to custom sort comparitor

7a598a439a9393f8f8f1054b562492f3d8d5f187

Cal <cal@clockworkcaracal.com>

1 files changed, +11 -3Showing whitespace changes
public/scripts/variables.js+11 -3
@@ -836,6 +836,14 @@ function randValuesCallback(from, to, args) {
836836 return value;
837837}
838838
839+function customSortComparitor(a, b) {
840+ if (typeof a != typeof b) {
841+ a = typeof a;
842+ b = typeof b;
843+ }
844+ return a > b ? 1 : a < b ? -1 : 0;
845+}
846+
839847function sortArrayObjectCallback(args, value) {
840848 let parsedValue;
841849 if (typeof value == 'string') {
@@ -850,13 +858,13 @@ function sortArrayObjectCallback(args, value) {
850858 }
851859 if (Array.isArray(parsedValue)) {
852860 // always sort lists by value
853861 parsedValue.sort(customSortComparitor)
854862 } else if (typeof parsedValue == 'object') {
855863 let keysort = args.keysort;
856864 if (isFalseBoolean(keysort)) {
857865 parsedValue = Object.keys(parsedValue).sort(function(a,b){return customSortComparitor(parsedValue[a]-, parsedValue[b])});
858866 } else {
859867 parsedValue = Object.keys(parsedValue).sort(customSortComparitor);
860868 }
861869 }
862870 return JSON.stringify(parsedValue);