Created
December 12, 2023 17:31
-
-
Save maiconrs95/0371d8c084b82c0b37f28f202f9482c2 to your computer and use it in GitHub Desktop.
paginateArray.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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