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

Array.sortBy #30

Open
El-Dringo-Brannde opened this issue Aug 14, 2018 · 3 comments
Open

Array.sortBy #30

El-Dringo-Brannde opened this issue Aug 14, 2018 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@El-Dringo-Brannde
Copy link
Owner

El-Dringo-Brannde commented Aug 14, 2018

This functionality should be Kindly borrowed from Lodash's _.sortBy

A user should be able to pass in an array of objects and be able to sort them by a value, or a function that returns a truthy value.

Differently from Lodash however, it should keep the original format of whatever data is in the array.

Example:

let users = [
  { 'user': 'fred',   'age': 48 },
  { 'user': 'barney', 'age': 36 },
  { 'user': 'fred',   'age': 40 },
  { 'user': 'barney', 'age': 34 }
];
 
users.sortBy(user => user.user);

console.log(users)
// => objects for [{'barney', 36}, {'barney', 34}, {'fred', 48}, {'fred', 40}]
 
users.sortBy(['user', 'age']);

console.log(users)
// => objects for [{'barney', 34}, {'barney', 36}, {'fred', 40}, {'fred', 48}]

Update README and tests accordingly.

@El-Dringo-Brannde El-Dringo-Brannde added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Aug 14, 2018
@decarbonite
Copy link
Contributor

If it's Array.sortBy why pass in the array inside the function as a parameter, shouldn't it be Array.sortBy(funcToBeApplied) or something?

@El-Dringo-Brannde
Copy link
Owner Author

Whoops, too much copy pasta, you're right. I'll update it when I get home.

@El-Dringo-Brannde
Copy link
Owner Author

@decarbonite Heavily belated, but finally done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants