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

Created on 19 Apr 2018  ·  9Comments  ·  Source: jashkenas/underscore

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

I think this is a big problem :stuck_out_tongue:

bug fixed

Most helpful comment

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

All 9 comments

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]

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.

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

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

gracias. this one bit us too today.

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?

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.

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

Thanks @jashkenas

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markvr picture markvr  ·  3Comments

zackschuster picture zackschuster  ·  5Comments

acl0056 picture acl0056  ·  5Comments

jdalton picture jdalton  ·  4Comments

marcalj picture marcalj  ·  5Comments