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.
 
 
 
 
 
 

23 lines
588 B

'use strict';
// Numeric sort of object keys (converted from string to number), to sort
// sparse array keys.
function numericSort(arr) {
Array.prototype.sort.call(arr, (a, b) => {
let an = Number(a);
let bn = Number(b);
if (an > bn) { return 1; }
if (an < bn) { return -1; }
return 0;
});
return arr;
}
exports.numericSort = numericSort;
// Comparison function for numbers (no coercion).
function numberCompare(a, b) {
if (a > b) { return 1; }
if (a < b) { return -1; }
return 0;
}
exports.numberCompare = numberCompare;