Skip to main content
Back to problems
#2821
Medium JavaScript

Delay the resolution of each promise

74.6% acceptance
Mar 31, 2026
18
5
Given an array functions and a number ms, return a new array of functions. functions is an array of functions that return promises. ms represents the delay duration in milliseconds. It determines the amount of time to wait before resolving or rejecting each promise in the new array. Each function in the new array should return a promise that resolves or rejects after an additional delay of ms milliseconds, preserving the order of the original functions array. The delayAll function should ensure that each promise from functions is executed with a delay, forming the new array of functions returning delayed promises.

Solution

TypeScript
Time O(1)
Space O(1)
LeetCode
solution.ts
type Fn = () => Promise<any>;

function delayAll(functions: Fn[], ms: number): Fn[] {
  return functions.map((fn) => () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
    fn().then(resolve).catch(reject);
    }, ms);
  });
  });
}