mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Ensure _.sortBy moves symbols to the end.
This commit is contained in:
24
lodash.js
24
lodash.js
@@ -4062,27 +4062,27 @@
|
|||||||
*/
|
*/
|
||||||
function compareAscending(value, other) {
|
function compareAscending(value, other) {
|
||||||
if (value !== other) {
|
if (value !== other) {
|
||||||
var valIsNull = value === null,
|
var valIsDefined = value !== undefined,
|
||||||
valIsUndef = value === undefined,
|
valIsNull = value === null,
|
||||||
valIsReflexive = value === value,
|
valIsReflexive = value === value,
|
||||||
valIsSymbol = isSymbol(value);
|
valIsSymbol = isSymbol(value);
|
||||||
|
|
||||||
var othIsNull = other === null,
|
var othIsDefined = other !== undefined,
|
||||||
othIsUndef = other === undefined,
|
othIsNull = other === null,
|
||||||
othIsReflexive = other === other,
|
othIsReflexive = other === other,
|
||||||
othIsSymbol = isSymbol(other);
|
othIsSymbol = isSymbol(other);
|
||||||
|
|
||||||
if ((valIsSymbol && !othIsSymbol) ||
|
if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
|
||||||
(!othIsNull && !othIsSymbol && value > other) ||
|
(valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
|
||||||
(valIsNull && !othIsUndef && othIsReflexive) ||
|
(valIsNull && othIsDefined && othIsReflexive) ||
|
||||||
(valIsUndef && othIsReflexive) ||
|
(!valIsDefined && othIsReflexive) ||
|
||||||
!valIsReflexive) {
|
!valIsReflexive) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((othIsSymbol && !valIsSymbol) ||
|
if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
|
||||||
(!valIsNull && !valIsSymbol && value < other) ||
|
(othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
|
||||||
(othIsNull && !valIsUndef && valIsReflexive) ||
|
(othIsNull && valIsDefined && valIsReflexive) ||
|
||||||
(othIsUndef && valIsReflexive) ||
|
(!othIsDefined && valIsReflexive) ||
|
||||||
!othIsReflexive) {
|
!othIsReflexive) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
16
test/test.js
16
test/test.js
@@ -20250,14 +20250,20 @@
|
|||||||
assert.deepEqual(actual, [3, 1, 2]);
|
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);
|
assert.expect(2);
|
||||||
|
|
||||||
var array = [NaN, undefined, null, 4, null, 1, undefined, 3, NaN, 2];
|
var symbol1 = Symbol ? Symbol('a') : null,
|
||||||
assert.deepEqual(_.sortBy(array), [1, 2, 3, 4, null, null, undefined, undefined, NaN, NaN]);
|
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), expected);
|
||||||
assert.deepEqual(_.sortBy(array), ['a', 'b', 'c', 'd', null, null, undefined, undefined, NaN, NaN]);
|
|
||||||
|
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) {
|
QUnit.test('should treat number values for `collection` as empty', function(assert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user