|
|
@ -183,9 +183,12 @@ function compareArrays (a, b) { |
|
|
|
* In the case of objects and arrays, we deep-compare |
|
|
|
* In the case of objects and arrays, we deep-compare |
|
|
|
* If two objects dont have the same type, the (arbitrary) type hierarchy is: undefined, null, number, strings, boolean, dates, arrays, objects |
|
|
|
* If two objects dont have the same type, the (arbitrary) type hierarchy is: undefined, null, number, strings, boolean, dates, arrays, objects |
|
|
|
* Return -1 if a < b, 1 if a > b and 0 if a = b (note that equality here is NOT the same as defined in areThingsEqual!) |
|
|
|
* Return -1 if a < b, 1 if a > b and 0 if a = b (note that equality here is NOT the same as defined in areThingsEqual!) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Function} _compareStrings String comparing function, returning -1, 0 or 1, overriding default string comparison (useful for languages with accented letters) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function compareThings (a, b) { |
|
|
|
function compareThings (a, b, _compareStrings) { |
|
|
|
var aKeys, bKeys, comp, i; |
|
|
|
var aKeys, bKeys, comp, i |
|
|
|
|
|
|
|
, compareStrings = _compareStrings || compareNSB; |
|
|
|
|
|
|
|
|
|
|
|
// undefined
|
|
|
|
// undefined
|
|
|
|
if (a === undefined) { return b === undefined ? 0 : -1; } |
|
|
|
if (a === undefined) { return b === undefined ? 0 : -1; } |
|
|
@ -200,8 +203,8 @@ function compareThings (a, b) { |
|
|
|
if (typeof b === 'number') { return typeof a === 'number' ? compareNSB(a, b) : 1; } |
|
|
|
if (typeof b === 'number') { return typeof a === 'number' ? compareNSB(a, b) : 1; } |
|
|
|
|
|
|
|
|
|
|
|
// Strings
|
|
|
|
// Strings
|
|
|
|
if (typeof a === 'string') { return typeof b === 'string' ? compareNSB(a, b) : -1; } |
|
|
|
if (typeof a === 'string') { return typeof b === 'string' ? compareStrings(a, b) : -1; } |
|
|
|
if (typeof b === 'string') { return typeof a === 'string' ? compareNSB(a, b) : 1; } |
|
|
|
if (typeof b === 'string') { return typeof a === 'string' ? compareStrings(a, b) : 1; } |
|
|
|
|
|
|
|
|
|
|
|
// Booleans
|
|
|
|
// Booleans
|
|
|
|
if (typeof a === 'boolean') { return typeof b === 'boolean' ? compareNSB(a, b) : -1; } |
|
|
|
if (typeof a === 'boolean') { return typeof b === 'boolean' ? compareNSB(a, b) : -1; } |
|
|
|