webapp/src/utils/splitToPages.ts

11 lines
287 B
TypeScript
Raw Normal View History

export function splitToPages<T>(arr: T[], startIndex: number, pageSize: number): T[][] {
return arr.slice(startIndex).reduce((acc, article, index) => {
if (index % pageSize === 0) {
acc.push([])
}
acc[acc.length - 1].push(article)
return acc
}, [] as T[][])
}