Implement a deeply nested object assigner simulating Lodash.set().
The set(obj, path, value) protocol intercepts nested JSON structures securely, traversing heavily. If arbitrary trees block the data node, it natively provisions objects or arrays logically to forge a clean traversal layout.
Implement the generic set function:
functionset(object, path, value){}
Core Traversing
The parameter path can be structurally provided as a direct string literal ('a.b.c' or 'a[0].b') or locally resolved array (['a', 'b', 'c']).
Function must walk down explicitly along the path mapping objects natively tracking state, assigning intermediate blocks, until it reaches the edge tree.
Once completely at the defined path index, securely lock in the desired value.
You must mutate and return the object back dynamically natively upon execution completion.
Edge Cases
Intermediate Auto-Creation: If the next identifier on your mapping denotes an array integer layout (0), auto-provision an empty Array wrapper structure ([]). If it denotes traditional identifiers (b), generate an explicit Object payload target instead ({}).
Destructive Overrides: If while traversing, the function stumbles across primitive structures inherently blocking traversal, your code must deterministically override and obliterate the primitive variable replacing it securely with the necessary Array or Object target internally.