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

Alias _.tail to _.last #5843

Closed
danielbayley opened this issue Apr 8, 2024 · 2 comments
Closed

Alias _.tail to _.last #5843

danielbayley opened this issue Apr 8, 2024 · 2 comments
Labels

Comments

@danielbayley
Copy link

danielbayley commented Apr 8, 2024

Having just added an optional parameter to _.last—to enable plucking the last n elements from an array in #5842, I also propose that _.tail be aliased to _.last, so that we have better consistency between _.head/_.first, and _.tail/_.last methods. The existing functionality of _.tail—to return all but the first array element—could instead now be done like this:

const array = [1, 2, 3 ,4]
_.tail(array, -1) // [2, 3, 4]

This might be a breaking change, so maybe one for v5… But could also exist as something like this wrapper function in the meantime…

import last from './last.js';

function tail(array, n = -1) {
    const results = last(array, n) || []
    return [results].flat()
}

export default tail;

See also #5841, which adds similar functionality to _.head/_.first.

@jdalton
Copy link
Member

jdalton commented Apr 11, 2024

Thank you @danielbayley! Per #5842 we are removing first/last in favor of built-in Array#at.

@danielbayley
Copy link
Author

danielbayley commented Apr 11, 2024

Thank you @danielbayley! Per #5842 we are removing first/last in favor of built-in Array#at.

@jdalton Same response as #5842 (comment):

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

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

No branches or pull requests

2 participants