let work = [
1,2,3,
5,6,7,
8,9,10]
let workCompleted = [11,
12,13,14,
15,16,17,
12]
function getPage(page = 1, size = 3) {
let wSize = work.length
let wcSize = workCompleted.length
let cur = page * size
let res = []
if(cur <= wSize) {
page = (page - 1) * size
res = work.slice(page, page + size)
}
if(cur > wSize && cur -wSize <= size) {
page = (page - 1) * size
res = work.slice(page, page + size)
size = cur -wSize;
res = [...res, ...workCompleted.slice(0, size)]
}
if(cur > wSize + size) {
let offset = (size - (wSize % size))% size
let newPage = Math.floor((cur - wSize) / size)
newPage = (newPage - 1) * size
res = workCompleted.slice(newPage + offset, newPage+size + offset)
}
return res
}
console.log(getPage(1))
console.log(getPage(2))
console.log(getPage(3))
console.log(getPage(4))
console.log(getPage(5))
console.log(getPage(6))
console