Explorer
Node.js

Write a function `promiseDivide(a, b)` that wraps the error-first callback pattern of division into a Promise.

Problem Statement

Write a function `promiseDivide(a, b)` that wraps the error-first callback pattern of division into a Promise.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Wrap callback-based code in new Promise((resolve, reject) => { ... }). šŸ’” Hint 2: Call resolve for success and reject for errors. šŸ’” Hint 3: return new Promise((resolve, reject) => { if (b === 0) reject(new Error("Division by zero")); else resolve(a / b); }); āœ… Solution: ```javascript function promiseDivide(a, b) { return new Promise((resolve, reject) => { if (b === 0) reject(new Error("Division by zero")); else resolve(a / b); }); } ```

Convert Callback to Promise

Easy
Write a function `promiseDivide(a, b)` that wraps the error-first callback pattern of division into a Promise.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
5