|
|
|
@ -132,9 +132,10 @@ function deepCopy (obj) { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Utility function for comparing things |
|
|
|
|
* Works for numbers, strings and booleans |
|
|
|
|
* Assumes type checking was already done (a and b already have the same type) |
|
|
|
|
*/ |
|
|
|
|
function compareNumbersAndStrings (a, b) { |
|
|
|
|
function compareNSB (a, b) { |
|
|
|
|
if (a < b) { return -1; } |
|
|
|
|
if (a > b) { return 1; } |
|
|
|
|
return 0; |
|
|
|
@ -153,12 +154,16 @@ function compareThings (a, b) { |
|
|
|
|
if (b === null) { return a === null ? 0 : 1; } |
|
|
|
|
|
|
|
|
|
// Numbers
|
|
|
|
|
if (typeof a === 'number') { return typeof b === 'number' ? compareNumbersAndStrings(a, b) : -1; } |
|
|
|
|
if (typeof b === 'number') { return typeof a === 'number' ? compareNumbersAndStrings(a, b) : 1; } |
|
|
|
|
if (typeof a === 'number') { return typeof b === 'number' ? compareNSB(a, b) : -1; } |
|
|
|
|
if (typeof b === 'number') { return typeof a === 'number' ? compareNSB(a, b) : 1; } |
|
|
|
|
|
|
|
|
|
// Strings
|
|
|
|
|
if (typeof a === 'string') { return typeof b === 'string' ? compareNumbersAndStrings(a, b) : -1; } |
|
|
|
|
if (typeof b === 'string') { return typeof a === 'string' ? compareNumbersAndStrings(a, b) : 1; } |
|
|
|
|
if (typeof a === 'string') { return typeof b === 'string' ? compareNSB(a, b) : -1; } |
|
|
|
|
if (typeof b === 'string') { return typeof a === 'string' ? compareNSB(a, b) : 1; } |
|
|
|
|
|
|
|
|
|
// Booleans
|
|
|
|
|
if (typeof a === 'boolean') { return typeof b === 'boolean' ? compareNSB(a, b) : -1; } |
|
|
|
|
if (typeof b === 'boolean') { return typeof a === 'boolean' ? compareNSB(a, b) : 1; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|