MediumPro challengePythonJavaScriptTypeScript

Partial Application

FunctionsClosures

Implement partial(fn, ...presetArgs) that returns a new function with
some arguments pre-filled. When the returned function is called, it prepends
presetArgs to any new arguments before forwarding to fn.

solve(presets, calls) drives the implementation using a variadic-sum
function.

Example

const add = (a, b, c) => a + b + c;
const add10 = partial(add, 10);
add10(5, 5)  // 20  → add(10, 5, 5)

Sample tests

Test #1Preset 10, call with different extra args
Input: [[10],[[5,5],[20],[1,2,3]]]
Output: [20,30,16]
Test #2Three presets + two more args
Input: [[1,2,3],[[4,5]]]
Output: [15]
Test #3No presets — works like a normal call
Input: [[],[[1,2,3]]]
Output: [6]
Test #4Preset 100 + extra 0
Input: [[100],[[0]]]
Output: [100]
Test #5No extra args vs. one extra arg
Input: [[5,5,5],[[],[10]]]
Output: [15,25]