Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
Write sequentialPromises(items, asyncFn) function that executes an async function for each array element sequentially (one after another).
sequentialPromises(items, asyncFn)
Requirements:
const items = ['item1', 'item2', 'item3']; const postData = async (item) => { await delay(100); return `posted: ${item}`; }; const results = await sequentialPromises(items, postData); // results = ['posted: item1', 'posted: item2', 'posted: item3'] // Total ~300ms (100ms * 3)
Run your code to see results.
Click the Run button above