Implement Promisify

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 Promisify

Approach

Return a wrapper function that accepts the same arguments plus appends a Node-style callback. Inside, create a new Promise and route the callback err to reject and result to resolve. This bridges callback-based APIs to promise-based code.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Promise Wrapper

Why It Works

Node.js callbacks follow the (err, result) convention, so the wrapper can reliably detect success vs failure and translate it into promise resolution or rejection.

Updated Mar 2026