Runtime correctness practice
Review the correctness rules that can't be captured by a single type annotation. A cloned profile must be detached, repeated references should remain shared inside the clone, equality needs a defined value model, and timed wrappers must follow their boundary rules. A state trace also needs to preserve earlier snapshots.
These independent tasks reuse the concepts from this unit on local fictional inputs. Do not add a universal clone or equality claim: implement the limited contract stated in each prompt. For timing questions, use the supplied clock and trace exactly when a callback runs. For state questions, distinguish an ignored event from a transition. Compiler assertions still check the reusable helper signatures, and runtime variants check identities, ordering, empty collections, and special values.
function deepClone<T>(value:T, seen=new WeakMap<object,unknown>()):T {
if(value===null || typeof value!=="object")return value;
if(seen.has(value))return seen.get(value) as T;
if(value instanceof Date)return new Date(value.getTime()) as T;
if(value instanceof Map){const out=new Map<unknown,unknown>();seen.set(value,out);for(const [k,v] of value)out.set(deepClone(k,seen),deepClone(v,seen));return out as T;}
if(value instanceof Set){const out=new Set<unknown>();seen.set(value,out);for(const item of value)out.add(deepClone(item,seen));return out as T;}
const out:unknown=Array.isArray(value)?[]:{}; seen.set(value,out);
for(const key of Object.keys(value))Object.defineProperty(out,key,{value:deepClone((value as Record<string,unknown>)[key],seen),enumerable:true,writable:true,configurable:true});
return out as T;
}
function solve(value:string):string[] {const input=JSON.parse(value) as {profile:{name:string};next:string};const copy=deepClone(input);copy.profile.name=input.next;return [input.profile.name,copy.profile.name];}
A complete implementation for the first scenario; trace its input before editing.