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

feat(last): add optional n elements parameter #5842

Closed
wants to merge 3 commits into from

Conversation

danielbayley
Copy link

@danielbayley danielbayley commented Apr 8, 2024

For example:

const array = [1,2,3,4]

_.last(array, { n: 2 }) // [3, 4]

_.last(array) // 4

[array].map(_.last) // [4]

@Trott
Copy link

Trott commented Apr 8, 2024

Adding this feature seems like it will break use cases where last() is used as a callback to Array.prototype.map() and similar functions.

It also seems like there's a footgun where .last([1], 500) returns 1 but .last([1,2,3], 500) returns an array.

@danielbayley
Copy link
Author

Adding this feature seems like it will break use cases where last() is used as a callback to Array.prototype.map() and similar functions.

@Trott @blikblum See fix, and response in #5841 (comment)

Fair point. My first contribution to this project, so not entirely sure what the design goal specifics are… But my assumption was that pure functional methods—with strict arity—were for lodash/fp?

An alternative approach might be to have something like lastN/tailN additional methods…

@jdalton
Copy link
Member

jdalton commented Apr 11, 2024

Our last method will be dropped for Array.prototype.at as in array.at(-1):
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at

@jdalton jdalton closed this Apr 11, 2024
@danielbayley
Copy link
Author

Our last method will be dropped for Array.prototype.at as in array.at(-1): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at

@jdalton That’s nice, but it doesn’t give you a range as is the point of this PR…

@jdalton
Copy link
Member

jdalton commented Apr 11, 2024

Are you thinking of https://lodash.com/docs/4.17.15#takeRight ?

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

Successfully merging this pull request may close these issues.

None yet

3 participants