-
Notifications
You must be signed in to change notification settings - Fork 323
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(toFilled): add toFilled #154
Conversation
@wondonghwi is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
Co-authored-by: jgjgill <79239852+jgjgill@users.noreply.github.com>
Thanks for your great contribution! I wanted to discuss the behavior of One key difference I've noticed is that What are your thoughts on this? |
Hello @raon0211, Based on my observations and tests, it appears that Lodash's fill function does indeed support negative indices. Given this, it seems appropriate that toFilled, as well as esToolkit's fill function, should also support negative indices to maintain consistency. Here is an example that demonstrates the behavior: Given this behavior, I believe it would be beneficial to enhance both toFilled and esToolkit's fill functions to support negative indices. I would be interested in working on this enhancement if it is deemed necessary. What are your thoughts on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Got this. Could you fix the behavior for |
Sure :) I will raise this issue and proceed to modify the fill function accordingly! |
close: #118
The fill function was added to es-toolkit, and since fill mutates the original array, a new function that does not modify the original array was needed. To address this, we added a new function, toFilled.
I have added a function called toFilled that does not modify the original array. This function fills a specified portion of an array with a given value but returns a new array instead of modifying the original one. Additionally, this function allows for the use of negative indices, meaning you can specify positions from the end of the array backward. The toFilled function works similarly to the fill function but stands out by not altering the original array.
In the benchmark results, since lodash does not have a toFilled function, I compared it with lodash’s fill function. The comparison showed that the toFilled function performed better in terms of performance.
The implementation of this function was inspired by this issue.