All files / array/operator chunkBySize.ts

100% Statements 15/15
100% Branches 4/4
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2042x 45x 45x 45x 45x 1423x 1423x 235x 235x 235x     41x 2x   41x        
export const chunkBySize = (chunkSize: number) =>  <T>(array: T[]): T[][] => {
  const result = [];
  let chunk = [];
  let count = 0;
  for (const t of array) {
    chunk.push(t);
    if (++count === chunkSize) {
      count = 0;
      result.push(chunk);
      chunk = [];
    }
  }
  if (count !== 0) {
    result.push(chunk);
  }
  return result;
 
};