mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
merging #532 -- allow string as iterator on sortBy
This commit is contained in:
@@ -238,6 +238,10 @@ $(document).ready(function() {
|
||||
|
||||
var list = [undefined, 4, 1, undefined, 3, 2];
|
||||
equal(_.sortBy(list, _.identity).join(','), '1,2,3,4,,', 'sortBy with undefined values');
|
||||
|
||||
var list = ["one", "two", "three", "four", "five"];
|
||||
var sorted = _.sortBy(list, 'length');
|
||||
equal(sorted.join(' '), 'one two four five three', 'sorted by length');
|
||||
});
|
||||
|
||||
test('collections: groupBy', function() {
|
||||
|
||||
@@ -262,7 +262,8 @@
|
||||
};
|
||||
|
||||
// Sort the object's values by a criterion produced by an iterator.
|
||||
_.sortBy = function(obj, iterator, context) {
|
||||
_.sortBy = function(obj, val, context) {
|
||||
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
||||
return _.pluck(_.map(obj, function(value, index, list) {
|
||||
return {
|
||||
value : value,
|
||||
|
||||
Reference in New Issue
Block a user