diff --git a/lodash.js b/lodash.js index 640890f5f..a2f69fe8a 100644 --- a/lodash.js +++ b/lodash.js @@ -4062,27 +4062,27 @@ */ function compareAscending(value, other) { if (value !== other) { - var valIsNull = value === null, - valIsUndef = value === undefined, + var valIsDefined = value !== undefined, + valIsNull = value === null, valIsReflexive = value === value, valIsSymbol = isSymbol(value); - var othIsNull = other === null, - othIsUndef = other === undefined, + var othIsDefined = other !== undefined, + othIsNull = other === null, othIsReflexive = other === other, othIsSymbol = isSymbol(other); - if ((valIsSymbol && !othIsSymbol) || - (!othIsNull && !othIsSymbol && value > other) || - (valIsNull && !othIsUndef && othIsReflexive) || - (valIsUndef && othIsReflexive) || + if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || !valIsReflexive) { return 1; } - if ((othIsSymbol && !valIsSymbol) || - (!valIsNull && !valIsSymbol && value < other) || - (othIsNull && !valIsUndef && valIsReflexive) || - (othIsUndef && valIsReflexive) || + if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || !othIsReflexive) { return -1; } diff --git a/test/test.js b/test/test.js index 15c83081d..201084897 100644 --- a/test/test.js +++ b/test/test.js @@ -20250,14 +20250,20 @@ assert.deepEqual(actual, [3, 1, 2]); }); - QUnit.test('should move `null`, `undefined`, and `NaN` values to the end', function(assert) { + QUnit.test('should move symbol, `null`, `undefined`, and `NaN` values to the end', function(assert) { assert.expect(2); - var array = [NaN, undefined, null, 4, null, 1, undefined, 3, NaN, 2]; - assert.deepEqual(_.sortBy(array), [1, 2, 3, 4, null, null, undefined, undefined, NaN, NaN]); + var symbol1 = Symbol ? Symbol('a') : null, + symbol2 = Symbol ? Symbol('b') : null, + array = [NaN, undefined, null, 4, symbol1, null, 1, symbol2, undefined, 3, NaN, 2], + expected = [1, 2, 3, 4, symbol1, symbol2, null, null, undefined, undefined, NaN, NaN]; - array = [NaN, undefined, null, 'd', null, 'a', undefined, 'c', NaN, 'b']; - assert.deepEqual(_.sortBy(array), ['a', 'b', 'c', 'd', null, null, undefined, undefined, NaN, NaN]); + assert.deepEqual(_.sortBy(array), expected); + + array = [NaN, undefined, symbol1, null, 'd', null, 'a', symbol2, undefined, 'c', NaN, 'b']; + expected = ['a', 'b', 'c', 'd', symbol1, symbol2, null, null, undefined, undefined, NaN, NaN]; + + assert.deepEqual(_.sortBy(array), expected); }); QUnit.test('should treat number values for `collection` as empty', function(assert) {