Skip to content

Instantly share code, notes, and snippets.

@TrejGun
Last active August 4, 2021 02:15
Show Gist options
  • Save TrejGun/73d717cd8812a14b951af90087693af3 to your computer and use it in GitHub Desktop.
Save TrejGun/73d717cd8812a14b951af90087693af3 to your computer and use it in GitHub Desktop.
chunkBy
export const chunkBy = <T>(array: Array<T>, size = 1): Array<Array<T>> => {
const arrayChunks: Array<Array<T>> = [];
for (let pointer = 0; pointer < array.length; pointer += size) {
arrayChunks.push(array.slice(pointer, pointer + size));
}
return arrayChunks;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment