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

marcalj picture marcalj  Â·  5Comments

umarfarooq125 picture umarfarooq125  Â·  8Comments

githublyp picture githublyp  Â·  3Comments

haggholm picture haggholm  Â·  8Comments

afranioce picture afranioce  Â·  8Comments