mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
add order by behaviour with array similar to get method (#4453)
* add order by behaviour with array similar to get method * remove typo for fixing orderby iteratee assignment * lint fixes * update test case * include package-lock from master * Add identity function for default iteratee
This commit is contained in:
committed by
John-David Dalton
parent
ad38dc0115
commit
5df1777477
@@ -11,11 +11,29 @@ describe('orderBy', function() {
|
||||
{ 'a': 'y', 'b': 2 }
|
||||
];
|
||||
|
||||
var nestedObj = [
|
||||
{ id: '4', address: { zipCode: 4, streetName: 'Beta' } },
|
||||
{ id: '3', address: { zipCode: 3, streetName: 'Alpha' } },
|
||||
{ id: '1', address: { zipCode: 1, streetName: 'Alpha' } },
|
||||
{ id: '2', address: { zipCode: 2, streetName: 'Alpha' } },
|
||||
{ id: '5', address: { zipCode: 4, streetName: 'Alpha' } },
|
||||
];
|
||||
|
||||
|
||||
it('should sort by a single property by a specified order', function() {
|
||||
var actual = orderBy(objects, 'a', 'desc');
|
||||
assert.deepStrictEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
|
||||
});
|
||||
|
||||
it('should sort by nested key in array format', () => {
|
||||
var actual = orderBy(
|
||||
nestedObj,
|
||||
[['address','zipCode'], ['address.streetName']],
|
||||
['asc', 'desc'],
|
||||
);
|
||||
assert.deepStrictEqual(actual, [nestedObj[2], nestedObj[3], nestedObj[0], nestedObj[1]], nestedObj[4]);
|
||||
});
|
||||
|
||||
it('should sort by multiple properties by specified orders', function() {
|
||||
var actual = orderBy(objects, ['a', 'b'], ['desc', 'asc']);
|
||||
assert.deepStrictEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
|
||||
|
||||
Reference in New Issue
Block a user