Implement _.partial()

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start•← → to step•? all shortcuts

Solution Guide: Implement _.partial()

Approach

Return a new function that prepends the preset arguments to any later arguments, then calls the original function with the combined list. Extend with placeholder support by scanning preset arguments for a sentinel symbol and replacing those positions with later arguments in order.

Complexity Analysis

Time
O(1)
Space
O(n) where n is the preset argument count

Pattern

Partial Application

Why It Works

Closures capture the preset arguments so they persist across calls, and spread syntax cleanly concatenates preset and later arguments into a single invocation of the original function.

Updated Mar 2026