const getData = (page: number = 1, pageSize: number = 10, totalData: any = []): IPost[] => {
const { length } = totalData
const tableData = {
data: [],
page,
pageSize,
length,
}
if (pageSize >= length) {
tableData.data = totalData
tableData.page = 1
} else {
const num = pageSize * (page - 1)
if (num < length) {
const startIndex = num
const endIndex = num + pageSize - 1
tableData.data = totalData.filter(
(_: any, index: number) => index >= startIndex && index <= endIndex
)
} else {
const size = length / pageSize
const rest = length % pageSize
if (rest > 0) {
tableData.page = size + 1
tableData.data = totalData.filter(
(_: any, index: number) => index >= pageSize * size && index <= length
)
} else if (rest === 0) {
tableData.page = size
tableData.data = totalData.filter(
(_: any, index: number) => index >= pageSize * (size - 1) && index <= length
)
}
}
}
return tableData.data
}