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

_.chunk not working as excepted #195

Open
dermellor opened this issue May 9, 2015 · 1 comment
Open

_.chunk not working as excepted #195

dermellor opened this issue May 9, 2015 · 1 comment
Labels
after modules This should be postponed until after modularization (temporary label, see #220) bug docs question

Comments

@dermellor
Copy link

The following statement

_.chunk(["one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"],3,"-")

returns an array with 5 arrays, where the last one contains one item with the padding ("-"). This is obviously incorrect.

@carltonf
Copy link

I think it's somewhat by design, the way chunk handles empty array with padding is like this:

_.chunk([], 3, '-')  // => ['-'], maybe this should be []?

In your case, the leftover part after splitting is [], so you get ['-'].
The current implementation of chunk actually needs clients check the length of array and chunk size beforehand, quite inconvenient.
I'm not sure, need someone with more knowledge on this.

@jgonggrijp jgonggrijp added after modules This should be postponed until after modularization (temporary label, see #220) bug docs question labels Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
after modules This should be postponed until after modularization (temporary label, see #220) bug docs question
Projects
None yet
Development

No branches or pull requests

3 participants