Problem statement
Write function solution(logs, fields). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. logs:JSON[], fields:string[]. Match object keys case-insensitively against fields without trimming. Replace the entire matching value with '[REDACTED]'. Recurse into other objects and arrays; retain primitives and null. Preserve all keys, including '__proto__'. Maximum depth 20. Return a new array in input order. 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
[
[
{
"token": "abc",
"message": "ok"
}
],
[
"token"
]
]Return value
[
{
"token": "[REDACTED]",
"message": "ok"
}
]Example 2
Function arguments
[
[
{
"nested": {
"PASSWORD": "p"
},
"tags": [
"x"
]
}
],
[
"password"
]
]Return value
[
{
"nested": {
"PASSWORD": "[REDACTED]"
},
"tags": [
"x"
]
}
]Example 3
Function arguments
[
[
{
"user": {
"name": "Alex"
},
"token": null
}
],
[
"token"
]
]Return value
[
{
"user": {
"name": "Alex"
},
"token": "[REDACTED]"
}
]