HardPro challengeJavaScriptTypeScript

Hook Composition

ReactHooksComposition

Implement useCombined(initials) that combines multiple counter states
into one. Returns { get, increment(key), reset() }.

solve(initials, ops) drives the hook, returns final state.

Sample tests

Test #1No ops
Input: [{"k":10},[]]
Output: {"k":10}
Test #2Increment one
Input: [{"a":0,"b":0},[{"key":"a","type":"increment"}]]
Output: {"a":1,"b":0}
Test #3Increment twice
Input: [{"x":5},[{"key":"x","type":"increment"},{"key":"x","type":"increment"}]]
Output: {"x":7}
Test #4Reset works
Input: [{"a":0},[{"key":"a","type":"increment"},{"type":"reset"}]]
Output: {"a":0}
Test #5Multiple keys
Input: [{"a":0,"b":0},[{"key":"a","type":"increment"},{"key":"b","type":"increment"},{"key":"a","type":"increment"}]]
Output: {"a":2,"b":1}