|
6546 | 6546 |
|
6547 | 6547 | (function() {
|
6548 | 6548 | var objects = [
|
6549 |
| - { 'num': 991 }, |
6550 |
| - { 'num': 212 }, |
6551 |
| - { 'num': 11 }, |
6552 |
| - { 'num': 16 }, |
6553 |
| - { 'num': 74 }, |
6554 |
| - { 'num': 0 }, |
6555 |
| - { 'num': 1515 } |
| 6549 | + { 'a': 'x', 'b': 3 }, |
| 6550 | + { 'a': 'y', 'b': 4 }, |
| 6551 | + { 'a': 'x', 'b': 1 }, |
| 6552 | + { 'a': 'y', 'b': 2 } |
6556 | 6553 | ];
|
6557 | 6554 |
|
6558 | 6555 | test('should sort in ascending order', 1, function() {
|
6559 | 6556 | var actual = _.pluck(_.sortBy(objects, function(object) {
|
6560 |
| - return object.num; |
6561 |
| - }), 'num'); |
| 6557 | + return object.b; |
| 6558 | + }), 'b'); |
6562 | 6559 |
|
6563 |
| - deepEqual(actual, [0, 11, 16, 74, 212, 991, 1515]); |
| 6560 | + deepEqual(actual, [1, 2, 3, 4]); |
6564 | 6561 | });
|
6565 | 6562 |
|
6566 | 6563 | test('should perform a stable sort (test in IE > 8, Opera, and V8)', 1, function() {
|
|
6617 | 6614 | });
|
6618 | 6615 |
|
6619 | 6616 | test('should work with an array for `callback`', 1, function() {
|
6620 |
| - var objects = [ |
6621 |
| - { 'a': 'x', 'b': 3 }, |
6622 |
| - { 'a': 'y', 'b': 4 }, |
6623 |
| - { 'a': 'x', 'b': 1 }, |
6624 |
| - { 'a': 'y', 'b': 2 } |
6625 |
| - ]; |
6626 |
| - |
6627 | 6617 | var actual = _.sortBy(objects, ['a', 'b']);
|
6628 | 6618 | deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
|
6629 | 6619 | });
|
6630 | 6620 |
|
| 6621 | + test('should coerce arrays returned from a `callback`', 1, function() { |
| 6622 | + var actual = _.sortBy(objects, function(object) { |
| 6623 | + var result = [object.a, object.b]; |
| 6624 | + result.toString = function() { return String(this[0]); }; |
| 6625 | + return result; |
| 6626 | + }); |
| 6627 | + |
| 6628 | + deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]); |
| 6629 | + }); |
| 6630 | + |
6631 | 6631 | test('should work with a string for `callback`', 1, function() {
|
6632 |
| - var actual = _.pluck(_.sortBy(objects, 'num'), 'num'); |
6633 |
| - deepEqual(actual, [0, 11, 16, 74, 212, 991, 1515]); |
| 6632 | + var actual = _.pluck(_.sortBy(objects, 'b'), 'b'); |
| 6633 | + deepEqual(actual, [1, 2, 3, 4]); |
6634 | 6634 | });
|
6635 | 6635 |
|
6636 | 6636 | test('should work with an object for `collection`', 1, function() {
|
|
0 commit comments