1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/utils/paginate.ts

23 lines
547 B
TypeScript
Raw Normal View History

export const paginate = (data: any[], limit: number) => {
const result = [];
let currentIdx = 0;
if (data.length <= currentIdx) {
return data;
}
while (currentIdx < data.length) {
if (currentIdx === 0) {
currentIdx += limit;
const page = data.slice(0, currentIdx);
result.push(page);
} else {
const page = data.slice(currentIdx, currentIdx + limit);
currentIdx += limit;
result.push(page);
}
}
return result;
};