Problem statement
Write function solution(target, patch). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. target and patch are JSON values. A nonobject patch (including null and arrays) replaces the entire target. For an object patch, start with {} if target is not an object. Delete keys whose patch value is null; recursively apply all other keys. Replace arrays wholesale. Preserve input and treat '__proto__' and 'constructor' as ordinary data keys. Maximum depth 20. 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
[
{
"a": 1,
"b": 2
},
{
"a": null,
"c": 3
}
]Return value
{
"b": 2,
"c": 3
}Example 2
Function arguments
[
{
"nested": {
"a": 1,
"b": 2
}
},
{
"nested": {
"a": 3
}
}
]Return value
{
"nested": {
"a": 3,
"b": 2
}
}Example 3
Function arguments
[
{
"a": true
},
{
"a": false
}
]Return value
{
"a": false
}