Skip to content

Instantly share code, notes, and snippets.

@anymaniax
Created October 16, 2017 09:33
Show Gist options
  • Save anymaniax/c9c320ec00407601f551ad61bde0df5a to your computer and use it in GitHub Desktop.
Save anymaniax/c9c320ec00407601f551ad61bde0df5a to your computer and use it in GitHub Desktop.
function chunk<T>(arr: T[], size: number = 1): T[][] {
return arr.reduce((acc, it, i) => i % size === 0 ? [...acc, arr.slice(i, i + size)] : acc, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment