Problem statement
Write function solution(items, page, pageSize). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. items is an array of JSON values; page and pageSize are numbers. Use pageSize=10 if it is not a positive integer, and cap it at 100. totalPages is ceil(items.length/pageSize). Use page=1 if it is not a positive integer, and clamp it to max(1,totalPages) if it exceeds the last page. Return {items:page slice,total:item count,page:adjusted page,pageSize:adjusted size,totalPages}. For an empty input, page is 1 and totalPages is 0. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
1,
2,
3,
4,
5
],
2,
2
]Return value
{
"items": [
3,
4
],
"total": 5,
"page": 2,
"pageSize": 2,
"totalPages": 3
}Example 2
Function arguments
[ [], 9, 10 ]
Return value
{
"items": [],
"total": 0,
"page": 1,
"pageSize": 10,
"totalPages": 0
}Example 3
Function arguments
[
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
2,
10
]Return value
{
"items": [
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
"total": 20,
"page": 2,
"pageSize": 10,
"totalPages": 2
}