2798. Chunk Array
My accepted JavaScript solution to LeetCode problem 2798, Chunk Array, running in 52ms.
- Difficulty: Easy
- JavaScript
- Runtime 52ms
- Memory 55.8MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 52ms, memory 55.8MB, accepted 2026-01-01.
/**
* @param {Array} arr
* @param {number} size
* @return {Array}
*/
var chunk = function(arr, size) {
const result = [];
for (let i = 0; i < arr.length; i += size) {
result.push(arr.slice(i, i + size));
}
return result;
};