Explorer
Node.js

Write a function `processBatch(items, batchSize, fn)` that processes items in batches of batchSize, calling fn with each batch.

Problem Statement

Write a function `processBatch(items, batchSize, fn)` that processes items in batches of batchSize, calling fn with each batch.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Slice the array into chunks of batchSize. šŸ’” Hint 2: Iterate with a step of batchSize using a for loop. šŸ’” Hint 3: for (let i = 0; i < items.length; i += batchSize) fn(items.slice(i, i + batchSize)); āœ… Solution: ```javascript function processBatch(items, batchSize, fn) { const results = []; for (let i = 0; i < items.length; i += batchSize) { results.push(fn(items.slice(i, i + batchSize))); } return results; } ```

Batch Processing

Medium
Write a function `processBatch(items, batchSize, fn)` that processes items in batches of batchSize, calling fn with each batch.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[[1,2,3],[4,5,6],[7]]