Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created May 15, 2019 14:27
Show Gist options
  • Save BetterProgramming/da0346fe86c18f15721ea11e1f70ff67 to your computer and use it in GitHub Desktop.
Save BetterProgramming/da0346fe86c18f15721ea11e1f70ff67 to your computer and use it in GitHub Desktop.
export class ArrayUtils {
static chunk<T>(array: T[], chunkSize: number): T[][] {
const chunks: T[] = [];
let index = 0;
while(index < array.length){
chunks.push(array.slice(index, index + chunkSize);
index += chunkSize
}
return chunks;
}
}
@FreekMencke
Copy link

Should be:

export class ArrayUtils {
  static chunk<T>(array: T[], chunkSize: number): T[][] {
    const chunks: T[][] = [];

    let index = 0;
    while (index < array.length) {
      chunks.push(array.slice(index, index + chunkSize));
      index += chunkSize;
    }
    return chunks;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment