Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

orderBy should not reverse an array of objects #9566

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ function orderByFilter($parse){
v2 = v2.toLowerCase();
}
if (v1 === v2) return 0;
return v1 < v2 ? -1 : 1;
return v1 > v2 ? 1 : -1;
} else {
return t1 < t2 ? -1 : 1;
return t1 > t2 ? 1 : -1;
}
}
};
Expand Down
7 changes: 7 additions & 0 deletions test/ng/filter/orderBySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ describe('Filter: orderBy', function() {
expect(orderBy([2, 1, 3], ['-'])).toEqual([3, 2, 1]);
});

it('should maintain order in an array of objects if no predicate is provided', function() {
expect(orderBy([{a: 1}, {b: 2}, {c: 3}])).toEqualData([{a: 1}, {b: 2}, {c: 3}]);
expect(orderBy([{a: 1}, {b: 2}, {c: 3}], '')).toEqualData([{a: 1}, {b: 2}, {c: 3}]);
expect(orderBy([{a: 1}, {b: 2}, {c: 3}], [])).toEqualData([{a: 1}, {b: 2}, {c: 3}]);
expect(orderBy([{a: 1}, {b: 2}, {c: 3}], [''])).toEqualData([{a: 1}, {b: 2}, {c: 3}]);
});

it('shouldSortArrayInReverse', function() {
expect(orderBy([{a:15}, {a:2}], 'a', true)).toEqualData([{a:15}, {a:2}]);
expect(orderBy([{a:15}, {a:2}], 'a', "T")).toEqualData([{a:15}, {a:2}]);
Expand Down