underscore icon indicating copy to clipboard operation
underscore copied to clipboard

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

Open ksullivan opened this issue 8 years ago • 9 comments

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

I think this is a big problem :stuck_out_tongue:

ksullivan avatar Apr 19 '18 11:04 ksullivan

Wow... It almost looks like this was an intended change... https://github.com/jashkenas/underscore/pull/2513

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

ksullivan avatar Apr 19 '18 11:04 ksullivan

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 avatar Apr 19 '18 17:04 jashkenas

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

jridgewell avatar Apr 19 '18 17:04 jridgewell

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

jashkenas avatar Apr 19 '18 17:04 jashkenas

gracias. this one bit us too today.

lubelski avatar Apr 25 '18 19:04 lubelski

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?

andreialecu avatar May 21 '18 13:05 andreialecu

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.

tgolen avatar May 29 '18 17:05 tgolen

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

jashkenas avatar May 31 '18 21:05 jashkenas

Thanks @jashkenas

captbaritone avatar May 31 '18 23:05 captbaritone