Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_.orderBy does not accept iteratee path arrays #4438

Closed
samuelcolburn opened this issue Aug 23, 2019 · 1 comment
Closed

_.orderBy does not accept iteratee path arrays #4438

samuelcolburn opened this issue Aug 23, 2019 · 1 comment
Labels

Comments

@samuelcolburn
Copy link

samuelcolburn commented Aug 23, 2019

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.

@jdalton
Copy link
Member

jdalton commented Aug 30, 2019

Moved to #4453.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants