Closed
Description
I don't know if this is intended behavior, but _.orderBy
does not work with path arrays.
An example I created using the REPL in the docs:
var users = [
{ 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' } },
];
// Sort by `address.zipCode` in ascending order
// and by `address.streetName` in descending order.
// This works
_.orderBy(
users,
['address.zipCode', 'address.streetName'],
['asc', 'desc']
);
// This doesn't
_.orderBy(
users,
[['address','zipCode'], ['address.streetName']],
['asc', 'desc']
);
// => objects for [
// ['1', [1, 'Alpha']],
// ['2', [2, 'Alpha']],
// ['3', [3, 'Alpha']],
// ['4', [4, 'Beta']],
// ['5', [4, 'Alpha']]
// ]
REPL link: https://runkit.com/samuelcolburn/5d6023bcb4e038001412b42b
Expected Behavior
That a path array ['address', 'zipCode']
is treated the same as a dot-delimited path string'address.zipCode'
.
Actual Behavior
'address.zipCode'
works as expected. ['address', 'zipCode']
is not sorted at all.
My apologies if this is intended behavior or if all iteratees are treated this way, it was my assumption based on functions like _.get()
that these two types of paths were treated equivalently.