mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
revisions to #534, sortBy(undefined)
This commit is contained in:
@@ -235,6 +235,9 @@ $(document).ready(function() {
|
|||||||
var people = [{name : 'curly', age : 50}, {name : 'moe', age : 30}];
|
var people = [{name : 'curly', age : 50}, {name : 'moe', age : 30}];
|
||||||
people = _.sortBy(people, function(person){ return person.age; });
|
people = _.sortBy(people, function(person){ return person.age; });
|
||||||
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'stooges sorted by age');
|
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'stooges sorted by age');
|
||||||
|
|
||||||
|
var list = [undefined, 4, 1, undefined, 3, 2];
|
||||||
|
equal(_.sortBy(list, _.identity).join(','), '1,2,3,4,,', 'sortBy with undefined values');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('collections: groupBy', function() {
|
test('collections: groupBy', function() {
|
||||||
|
|||||||
@@ -270,8 +270,8 @@
|
|||||||
};
|
};
|
||||||
}).sort(function(left, right) {
|
}).sort(function(left, right) {
|
||||||
var a = left.criteria, b = right.criteria;
|
var a = left.criteria, b = right.criteria;
|
||||||
if (_.isUndefined(a)) return 1;
|
if (a === void 0) return 1;
|
||||||
if (_.isUndefined(b)) return -1;
|
if (b === void 0) return -1;
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
}), 'value');
|
}), 'value');
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user