MediumPro challengeJavaScriptTypeScript

Render Props Pattern

ReactPatternsFunctions

Implement Mouse({ render }) simulating a render-prop component.

solve(positions, renderFn) calls the simulated component for each
position; the component invokes render({ x, y }) and collects the result.

renderFn is given as a string of source code.

Sample tests

Test #1Single position
Input: [[{"x":1,"y":2}],"p => `(${p.x},${p.y})`"]
Output: ["(1,2)"]
Test #2Two positions
Input: [[{"x":0,"y":0},{"x":5,"y":5}],"p => `${p.x}+${p.y}=${p.x + p.y}`"]
Output: ["0+0=0","5+5=10"]
Test #3Empty positions
Input: [[],"p => \"\""]
Output: []
Test #4X only
Input: [[{"x":10,"y":20}],"p => p.x.toString()"]
Output: ["10"]
Test #5Multiplication
Input: [[{"x":-1,"y":-2}],"p => `${p.x * p.y}`"]
Output: ["2"]