Allow _.sortBy to accept an array for callback.

This commit is contained in:
John-David Dalton
2013-11-22 09:16:18 -08:00
parent 75ce4766d3
commit d8194c0886
9 changed files with 255 additions and 129 deletions

View File

@@ -74,8 +74,8 @@
['Windows 7', 'internet explorer', '8'],
['Windows XP', 'internet explorer', '7'],
['Windows XP', 'internet explorer', '6'],
['Windows 7', 'opera', '12'],
['Windows 7', 'opera', '11'],
//['Windows 7', 'opera', '12'],
//['Windows 7', 'opera', '11'],
['OS X 10.8', 'safari', '6'],
['Windows 7', 'safari', '5'],
['Windows XP', 'safari', '4']

View File

@@ -6512,6 +6512,18 @@
deepEqual(actual, [3, 1, 2]);
});
test('should work with an array for `callback`', 1, function() {
var objects = [
{ 'a': 'x', 'b': 3 },
{ 'a': 'y', 'b': 4 },
{ 'a': 'x', 'b': 1 },
{ 'a': 'y', 'b': 2 }
];
var actual = _.sortBy(objects, ['a', 'b']);
deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
});
test('should work with a string for `callback`', 1, function() {
var actual = _.pluck(_.sortBy(objects, 'num'), 'num');
deepEqual(actual, [0, 11, 16, 74, 212, 991, 1515]);