Skip to content

Instantly share code, notes, and snippets.

@maiconrs95
Created December 12, 2023 17:31
Show Gist options
  • Save maiconrs95/0371d8c084b82c0b37f28f202f9482c2 to your computer and use it in GitHub Desktop.
Save maiconrs95/0371d8c084b82c0b37f28f202f9482c2 to your computer and use it in GitHub Desktop.
paginateArray.ts
export const paginateArray = <T>(arr: T[] = [], size: number = 10): T[][] =>
arr.reduce<T[][]>((acc, val, i) => {
const idx = Math.floor(i / size);
const page = acc[idx] || (acc[idx] = []);
page.push(val);
return acc;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment