본문 바로가기

공부기록

공부기록, 2021-04-23(금), 011일차

- 페이지 구현 함수코드

fun getFilteredArticles(fromIndex: Int, itemsCountInAPage: Int): List<Article> {
val startIndex = articles.lastIndex - fromIndex
var endIndex = startIndex - itemsCountInAPage + 1

if ( endIndex < 0) {
endIndex = 0
}

val filteredArticles = mutableListOf<Article>()

// page 1 -> 99 downTo 90
// page 2 -> 89 downTO 80
for (i in startIndex downTo endIndex) {
filteredArticles.add(articles[i])
}

return filteredArticles
}