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

check length in _.first and _.last, fix #2495 #2513

Merged
merged 1 commit into from
Apr 24, 2016

Conversation

xcodebuild
Copy link
Contributor

Fix #2495

Now return undefined when use _.first or _.last on empty array.

Array.prototype[0] = 'boo';
_.first([]) // undefined

var arr = [];
arr[-1] = 'boo'
_.last(arr); // undefined

@coveralls
Copy link

Coverage Status

Coverage remained the same at 96.867% when pulling 507b858 on CodeFalling:check-length-in-first-last into 9c18116 on jashkenas:master.

@jridgewell jridgewell merged commit ce591c8 into jashkenas:master Apr 24, 2016
@jridgewell
Copy link
Collaborator

Thanks!

@psixdev
Copy link
Contributor

psixdev commented Sep 5, 2018

I would like to understand the motivation for this change. Why in this case first should return undefined instead of boo? Moreover, this does not work completely for sparse arrays:
image
image

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

Successfully merging this pull request may close these issues.

4 participants