Sobes.tech
Junior — Middle+

Step-by-step execution of functions returning promises

livecode

Task condition

You need to implement a function that takes an array of promise-returning functions and calls them sequentially, waiting for each to complete. After all functions have been executed, it should return an array-collection of the obtained values.

const fetchData = () => new Promise((resolve) => setTimeout(() => { 
    const value = Math.random(); 
    console.log(`promise run for: ${value}`); 
    resolve(value); 
}, 1000));

const sequentialPromises = (fnArray) => {};

(async () => { 
    const results = await sequentialPromises([fetchData, fetchData, fetchData]); 
    console.log(results); // should output [number, number, number]
})();