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

1.9.0 regression. Calling first or last on an empty array returns undefined. #2741

Closed
ksullivan opened this issue Apr 19, 2018 · 9 comments
Closed

Comments

@ksullivan
Copy link

With 1.9.0 _.first([], 10) returns undefined instead of [].

I think this is a big problem 😛

@ksullivan ksullivan changed the title 1.9.0 regression. Calling first or last on an empty array returns undefined 1.9.0 regression. Calling first or last on an empty array returns undefined. Apr 19, 2018
@ksullivan
Copy link
Author

Wow... It almost looks like this was an intended change... #2513

Personally, I think you would expect _.first([], 2) to be [] following from _.first([1,2,3], 2) being [1,2]

@jashkenas
Copy link
Owner

That does look like a nasty little regression to me — when called with the number of items specified explicitly. Any other opinions? @jridgewell?

That said, it does raise the question of what _.first([], 1) should be.

@jashkenas jashkenas added the bug label Apr 19, 2018
@jridgewell
Copy link
Collaborator

Whoops, poor review on my part. Passing in a n argument should always return an array.

@jashkenas
Copy link
Owner

No worries, we can do a 1.9.1 with any other cleanups that arise — plus maybe settling some of the other open PRs...

@lubelski
Copy link

gracias. this one bit us too today.

@andreialecu
Copy link

This one leads to very obscure bugs in edge cases in lots of various places in a bigger app in my case.

Should it not be a priority?

@tgolen
Copy link

tgolen commented May 29, 2018

This one also bit us. Luckily it was caught by some unit tests before we rolled it out live. I'd be grateful for a quick fix.

@jashkenas
Copy link
Owner

Alright! Underscore 1.9.1 is now published, with this bugfix in it.

@captbaritone
Copy link
Collaborator

Thanks @jashkenas

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

No branches or pull requests

7 participants