function update(target, updates)
{
if (typeof updates === "function")
return updates(target);
const changes = Object
.entries(updates)
.map(([key, value]) => [key, update(target[key], value)]);
return Array.isArray(target) ?
changes.reduce((array, [key, value]) =>
(array[key] = value, array), [...target]) :
{ ...target, ...Object.fromEntries(changes) };
}