Ensure _.sortBy performs a stable sort. [closes #59]

Former-commit-id: 09c5ff85ef0f1d054579ec4260a7f76d9c0da281
This commit is contained in:
John-David Dalton
2012-08-16 23:24:59 -07:00
parent 83d08e3aba
commit fab2d69fce
3 changed files with 36 additions and 6 deletions

View File

@@ -1112,6 +1112,28 @@
QUnit.module('lodash.sortBy');
(function() {
test('should perform a stable sort', function() {
function Pair(x, y) {
this.x = x;
this.y = y;
}
var collection = [
new Pair(1, 1), new Pair(1, 2),
new Pair(1, 3), new Pair(1, 4),
new Pair(1, 5), new Pair(1, 6),
new Pair(2, 1), new Pair(2, 2),
new Pair(2, 3), new Pair(2, 4),
new Pair(2, 5), new Pair(2, 6)
];
var actual = _.sortBy(collection, function(pair) {
return pair.x;
});
deepEqual(actual, collection);
});
test('supports the `thisArg` argument', function() {
var actual = _.sortBy([1, 2, 3], function(num) {
return this.sin(num);