Problem statement
Write function solution(input). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. The starter mishandles search filters and mutates its input. Repair it using AI and search if desired. You may rewrite the function body. input is {query:string,page:number,pageSize:number,tags:string[]}. Trim and lowercase query, preserving internal whitespace. Use page=1 unless page is a positive integer. Use pageSize=10 unless it is a positive integer, and cap valid sizes at 100. Trim and lowercase each tag, discard empty tags, and remove duplicates while preserving the first occurrence of each normalized tag. Return {query,page,pageSize,tags} without modifying the input. 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
[
{
"query": " Hello ",
"page": 2,
"pageSize": 20,
"tags": [
" JS ",
"js",
"React"
]
}
]Return value
{
"query": "hello",
"page": 2,
"pageSize": 20,
"tags": [
"js",
"react"
]
}Example 2
Function arguments
[
{
"query": " ",
"page": 0,
"pageSize": 0,
"tags": [
" ",
"A",
"a"
]
}
]Return value
{
"query": "",
"page": 1,
"pageSize": 10,
"tags": [
"a"
]
}Example 3
Function arguments
[
{
"query": "x",
"page": 1,
"pageSize": 10,
"tags": [
"中",
"中",
"日"
]
}
]Return value
{
"query": "x",
"page": 1,
"pageSize": 10,
"tags": [
"中",
"日"
]
}