Async & Promises

Implement Promisify

mediumJS SpecificJS / TS3 tests

Problem Statement

Implement `promisify(fn)`, which takes a Node.js-style asynchronous function that expects an error-first callback `(err, result) => void` as its last argument, and returns a function that returns a Promise.

Examples

Example 1:
function readFile(filename, callback) {
  if (!filename) callback(new Error('No file'));
  else callback(null, 'file content');
}
const readFileAsync = promisify(readFile);
const data = await readFileAsync('test.txt'); // 'file content'
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.