MediumPro challengeJavaScriptTypeScript
createContext + Provider
ReactContextPatterns
Implement createContext(defaultValue) returning { Provider, useContext }:
Provider({ value, children })— sets the active context value whilechildrenruns.useContext()— returns the current value (or default if no Provider).
solve(defaultVal, providers) builds nested providers and returns values
seen at each level.
Sample tests
Test #1No providers → default
Input: [0,[]]
Output: [0]
Test #2One provider
Input: [0,[1]]
Output: [0,1]
Test #3Two nested providers
Input: [10,[20,30]]
Output: [10,20,30]
Test #4Three nested
Input: [-1,[100,200,300]]
Output: [-1,100,200,300]
Test #5Default 42
Input: [42,[]]
Output: [42]