Problem, as an interviewer would state it:
"Implement chunk(array, size) — splitting the array into groups of the given size, matching lodash's own well-known _.chunk behavior, including the real, correct handling of a remainder that does not evenly divide."
Examples:
chunk([1,2,3,4,5,6], 2); // [[1,2],[3,4],[5,6]]
chunk([1,2,3,4,5], 2); // [[1,2],[3,4],[5]] -- a smaller final chunk
Clarifying questions expected:
- What is the real, correct behavior when the array length does NOT evenly divide by
size— should the final chunk simply be smaller? - What should happen if
sizeis larger than the entire array's own length? - What is the real, correct output for an invalid
size, like0or a negative number?
Code / implementation expected: Yes — real, direct proof of even splitting, a genuine remainder correctly producing a smaller final chunk, a size larger than the whole array, and a genuinely invalid size.