UNPKG

@codeplaydata/datasus

Version:

This application decompress the datasus micro data and serve as a gateway class.

36 lines (35 loc) 1.09 kB
// @filename: SplitIntoChunks.ts /** * Utility to split a list of items into fixed-size chunks. * * This is used by the JobOrchestrator to partition file lists and control * the max number of concurrent jobs handled by the JobScheduler. */ export class SplitIntoChunks { chunkSize; /** * @param chunkSize Desired size of each chunk (number of items per chunk). */ constructor(chunkSize) { this.chunkSize = chunkSize; } /** * Factory method to create a splitter with a defined chunk size. * @param chunkSize Number of items per chunk. */ static define(chunkSize) { return new SplitIntoChunks(chunkSize); } /** * Splits the given array into chunks of the configured size. * @param arr List of items to be partitioned. * @returns An array of arrays (chunks) keeping original order. */ exec(arr) { const chunks = []; for (let i = 0; i < arr.length; i += this.chunkSize) { chunks.push(arr.slice(i, i + this.chunkSize)); } return chunks; } }