Skip to content

Conversation

@ludofischer
Copy link

I have often wished to be able to reuse the same iterator, but reverse the order of the sort, when implementing filter-type controls.

This functionality has been already proposed (#910) but with a different API. I hope this one feels more idiomatic.

underscore.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I would have used a ternary: return reverse ? -1 : 1;

@ludofischer
Copy link
Author

I have updated the pull request to use a ternary, which does better fit stylistically with the rest of the codebase.

@braddunbar
Copy link
Collaborator

Hi @ludovicofischer! Thanks for your patch. I don't think we want to go this direction with _.sortBy though. For one thing, it's a breaking change that would make all existing calls to _.sortBy which contain a context argument sort in reverse. Also, it's generally best to avoid boolean arguments like this, especially when the fix is so straightforward (define a separate comparator).

@braddunbar braddunbar closed this Jan 7, 2013
@ludofischer
Copy link
Author

Yeah, it’s true no underscore method takes that kind of option modifying its behaviour.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants