Make _.sortByOrder support orders of "asc" and "desc".

This commit is contained in:
jdalton
2015-06-04 21:14:26 -07:00
parent 9e1f68d9eb
commit 56f199bd69
2 changed files with 26 additions and 21 deletions

View File

@@ -14525,14 +14525,18 @@
{ 'a': 'y', 'b': 2 }
];
test('should sort multiple properties by specified orders', 1, function() {
var actual = _.sortByOrder(objects, ['a', 'b'], [false, true]);
deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
test('should sort multiple properties by specified orders', 2, function() {
_.each([[false, true], ['desc', 'asc']], function(orders) {
var actual = _.sortByOrder(objects, ['a', 'b'], orders);
deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
});
});
test('should sort a property in ascending order when its order is not specified', 1, function() {
var actual = _.sortByOrder(objects, ['a', 'b'], [false]);
deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
test('should sort a property in ascending order when its order is not specified', 2, function() {
_.each([[false], ['desc']], function(orders) {
var actual = _.sortByOrder(objects, ['a', 'b'], orders);
deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
});
});
}());